Last active
September 12, 2016 00:22
-
-
Save dyspop/484f09eed4cee61f5d7901db0a621fb0 to your computer and use it in GitHub Desktop.
py sort challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
records = {('wendy', 'sanchez'): ['wunderkind','extraordinaire'], ('dan', 'black'): ['hacker','wannabe'], ('tim', 'black'): ['mad', 'genius', 'dontchaknow'], ('dan', 'garfield'): ['porg', 'rammer', 'snake charmer']} | |
sorted_last = ['black', 'black', 'garfield', 'sanchez'] | |
itered_records = [] | |
for last_name in sorted_last: | |
for key in records: | |
if key[1] == last_name: | |
if str([key + ('', records[key])]) not in itered_records: | |
itered_records.append(str([key + ('', records[key])])) | |
print key, records[key]` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is a microcosm of the real problem, so I just made a dummy set to illustrate the data
English: "If the stringified key value pair is not in the list of iterated records"
Yes, exactly that is what's being checked. The reason is because of the nested loop, the output has duplicates. We don't want duplicates.
precisely.
Your solution works pretty well! 🙇
I knew it had bad code smell and we tried doing sorted and we tried list comprehension but just a lambda sorted didn't occur to us. Thanks!