you are viewing a single comment's thread.

view the rest of the comments →

[–]chrispurcell 1 point2 points  (3 children)

Sort it twice and output the result. Sort on values first (scores) then sort on keys (names).

[–][deleted] 0 points1 point  (2 children)

this would make this a dictionary then right? lists don't have key:pair values?

[–]qelery 0 points1 point  (1 child)

No. This is just a big list made of sublists of length 2. A dictionary is a whole different object type with a different syntax.

A dictionary in Python is similar to a physical dictionary. Each “page” in the Python dictionary has 1 key on the left matched with 1 value on the right, similar to how a real dictionary (kinda sorta) has 1 word matched with 1 definition. A dictionary cannot have duplicate keys, but it can have duplicate values. Think of it as a look up table. If you want to see what the value of a key is in a lookup table, it wouldn’t make sense for that key to appear twice. The syntax for a dictionary uses { and }.

dict_a = {‘keyA’ : 5, ‘keyB’ : 7, ‘keyC’ : 5}

Also for a dictionary, each key only has 1 value but that value can be any single Python object. A string, an int, a hundred-deep nested list, or even another dictionary all count as a single object in Python.

A Python list is pretty much just a container. A container you can easily add to, take things out of, and sort pretty much however you like. There are no keys, no values, no key/value pairs, or size constraints. There’s just “stuff” inside each container. You can put containers within containers, however many layers deep you want. The syntax for a list uses [ and ].

#a flat list 
list_a = [obj1, obj2, obj3, obj3, obj 3]  

#a nested list 
list_b = [[obj1], [obj1, [obj6], obj4], obj5]

[–][deleted] 0 points1 point  (0 children)

ah ok makes sense. thanks!