![]() |
|
[Python] Dictionaries - Printable Version +- Hack Forums (https://hackforums.net) +-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444) +--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151) +---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118) +---- Thread: [Python] Dictionaries (/showthread.php?tid=5587725) |
Dictionaries - twistingtide - Mar 29, 2017 1. So I have a dictionary with the set up below The actor name, the movies they were in, and number to the right of the movies is the actors popularity dictionary = {1: ['Actor1', {movie1, movie3, movie7}, 89], 2:['Actor35, {movie3, movie7}, 57], 3:['Actor7',{movie7} 64], 4:['Actor9, {movie90} 3 ]} 2. So If someone types in the number 3 (Or any number within the length of my dictionary they go to that actor) into my input they go to Actor7 3. Once they are at actor 7 they look at ALL the movies the actor has been in and compare to all the movies the other actors have been in 4. If any of the actors share a movie append there name to a new list in the order of decreasing popularity(Popularity is the last element in the list) So it should look like this if they type in 3 because the only actors who share a movie with actor 7 is actor1 and actor35: final_list = [Actor1,Actor35] Thanks guys!!!🤗 * - (╯°□°)╯︵ ┻━━┻ - Mar 30, 2017 I'm on my phone, but to begin, you need to put the movies in a list instead of a dictionary (the {movies1...} part). * - hunter24957 - Mar 30, 2017 NGL, that's the worst layout of a dictionary I've ever seen. I would fix it for you but I'm still not sure what you're going for... Maybe use something like this: PHP Code And your dictionary keys are redundant, you can just use a list... * - (╯°□°)╯︵ ┻━━┻ - Mar 30, 2017 This feels like homework to me, so I'm going to make it fun! Good ol one liner :D Code actors = [* - Folks - Mar 30, 2017 (Mar 30, 2017 07:57 AM)(╯°□°)╯︵ ┻━━┻ Wrote: This feels like homework to me, so I'm going to make it fun! Good ol one liner :D One liners gave me an aneurism until I finally started to understand how to read through them lol * - (╯°□°)╯︵ ┻━━┻ - Mar 30, 2017 (Mar 30, 2017 08:16 AM)Folks Wrote: One liners gave me an aneurism until I finally started to understand how to read through them lol I wrote it out first and then I looked at it and figured I could one line it so I did. |