Python Forum
Import random from a txt file
Thread Rating:
  • 3 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Import random from a txt file
#5
(May-05-2017, 10:12 PM)ichabod801 Wrote: You're already prompting for a string, so you know how to do that. To see if a word or phrase is in a given title, you use the in operator:

if 'aid' in 'Raiders of the Lost Ark':
     print('match')
If you want to make that case insensitive, the standard way is to use the upper method of the two strings, which makes them both upper case. To check against all of the movie titles, you would loop through them, check each one. You could print each one as you find it, or append it to a list in case you wanted the matches for later processing.

Maybe ive been staring blankly at the code for too long haha thanks. Makes sense

So if I was to do this

if selection =='s':
  search = str(input("Please enter a string to search"))
if search in ([movies_list]):
   print(movies_list.index)
What would I need to change in order for it to display the strings that contain the user input?
Reply


Messages In This Thread
Import random from a txt file - by Liquid_Ocelot - May-05-2017, 08:47 PM
RE: Import random from a txt file - by snippsat - May-05-2017, 09:56 PM
RE: Import random from a txt file - by ichabod801 - May-05-2017, 10:12 PM
RE: Import random from a txt file - by Liquid_Ocelot - May-05-2017, 10:14 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Frequency in first digit from csv file, NO IMPORT bryan0901 6 2,869 May-28-2020, 09:50 AM
Last Post: bryan0901
  Import Python file with a name of a module in Stantard Library tiago_code 7 3,166 Dec-11-2019, 06:08 AM
Last Post: ICanIBB
  Import a Data from a text file maxcom 1 2,437 Apr-01-2018, 07:30 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020