Python Forum
Help printing any items that contains a keyword from a list
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help printing any items that contains a keyword from a list
#7
listb is all the movies, and it's still a bad variable name. Giving your variables descriptive names will not only help us understand your code and thus help you, it will also help you see for yourself where the problems are in your code. Back to listb:

favlist = list.append(listb)
What you are doing is appending a list of all the movies to the list of all the movies, which isn't very useful. Also, the result of that is None. The append method changes the list in place, and doesn't return anything (this is a difference between list methods and string methods. So, an example with actual lists:

Output:
>>> users = ['ichabod801', 'snippsat', 'Mekire'] >>> coders = users >>> people = users.append(coders) >>> print(people) None >>> print(users) ['ichabod801', 'snippsat', 'Mekire', ['ichabod801', 'snippsat', 'Mekire']]
So, if you want to do something with the matching movies, you should save them in a list:

matches = []
letter = input('Search title starting with the letter: ') # input is already returning a str, you don't need to convert it.
for movie in movies_list:
    if movie.startswith(letter):
        matches.append(movie)
        print(movie)
Now you've got a list of movies matching the last criteria. If you have a list of favorite movies (call it favorites), you can use the extend method to add the items in the matches list to the favorites list.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
RE: Help printing any items that contains a keyword from a list - by ichabod801 - May-06-2017, 11:20 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to parse and group hierarchical list items from an unindented string in Python? ann23fr 2 323 8 hours ago
Last Post: Pedroski55
  Collisions for items in a list Idents 3 2,353 Apr-06-2021, 03:48 PM
Last Post: deanhystad
  Removing items in a list cap510 3 2,386 Nov-01-2020, 09:53 PM
Last Post: cap510
  Help with Recursive solution,list items gianniskampanakis 8 3,692 Feb-28-2020, 03:36 PM
Last Post: gianniskampanakis
  Removing items from list slackerman73 8 4,512 Dec-13-2019, 05:39 PM
Last Post: Clunk_Head
  Find 'greater than' items in list johneven 2 4,516 Apr-05-2019, 07:22 AM
Last Post: perfringo
  How to add items within a list Mrocks22 2 2,732 Nov-01-2018, 08:46 PM
Last Post: Mrocks22
  printing list of random generated rectangles Zatoichi 8 7,456 Feb-18-2018, 06:34 PM
Last Post: buran
  How to keep duplicates and remove all other items in list? student8 1 4,997 Oct-28-2017, 05:52 AM
Last Post: heiner55

Forum Jump:

User Panel Messages

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