Python Programming Tutorial - 55 - Dictionary Multiple Key Sort

preview_player
Показать описание
Рекомендации по теме
Комментарии
Автор

For those who can't be arsed to write the names.

users = [
{'fname': 'Bucky', 'lname': 'Roberts'},
{'fname': 'Tom', 'lname': 'Roberts'},
{'fname': 'Bernie', 'lname': 'Zunks'},
{'fname': 'Jenna', 'lname': 'Hayes'},
{'fname': 'Johnny', 'lname': 'Concrete'},
{'fname': 'Donald', 'lname': 'Pump'},
{'fname': 'Ho-Lee', 'lname': 'Fuk'},
{'fname': 'Busta', 'lname': 'Nut'},
{'fname': 'Jedediah', 'lname': 'Springfield'},
{'fname': 'Super', 'lname': 'Mario'}
]

deimos
Автор

A big Thanks to Bucky. You are doing a great job. You are a great teacher. I have watched your complete series of python. And i gotta admit that i have developed a great interest in this language. God bless Bucky!

abhimalvekr
Автор

How come so little views??? This is free education. Thank you Bucky!

roymiller
Автор

Wow, was just looking for that like a week ago and couldn't find a proper answer... thanks mate!

Philippborchert
Автор

from what i've heard of the term, 'ship' is short for relationship i guess?? so like
"i ship brangelina"
or
"i ship (insert name) and (insert name)"
also, love the videos!! <3

hayleymarie
Автор

thanks you are back with python, cheers

michadziedziela
Автор

This method of sorting also works with three attribute keys, maybe more, as far as I can tell, while tinkering with it:

from operator import itemgetter


users2 = [{'ticker': 'AAPL', 'price': 201, 'mn': 'AA'},
{'ticker': 'GOOG', 'price': 800, 'mn': 'GG'},
{'ticker': 'F', 'price': 54, 'mn': 'FF'},
{'ticker': 'MSFT', 'price': 313, 'mn': 'MS'},
{'ticker': 'MSFT', 'price': 123, 'mn': 'MA'},
{'ticker': 'MSFT', 'price': 123, 'mn': 'MB'},
{'ticker': 'TUNA', 'price': 68, 'mn': 'TN'}, ]

for x in sorted(users2, key=itemgetter('ticker', 'price', 'mn')):
print(x)

tonyiguru
Автор

"Oh my god Autocomplete, can you not just type the rest of the code for me?"
lol

eyalpery
Автор

it's 2018 now and to ship somthing still didn't catch

israelkarity
Автор

omg man, you saved so much time of my life <3

GameRashid
Автор

Hey Bucky!!! thanks for the tutorial, as you mentioned it is the best tutorial in the universe, indeed it is. Just a quick question, As I am not able to find your source code after tutorial 41, so can you please share the link where I can find the tutorial source code from 42 to 56 tutorial...Thanks

saurabhksinhacfafrm
Автор

Just a question,

why sometimes the results from print appears as :

{'fname': 'Sally', 'lname': 'Jones'}

and other times as:

{'lname': 'Jones', 'fname': 'Sally'}

mgomezmunoz
Автор

if you are getting errors use first letter capital for all or dont use it .

vishal
Автор

from operator import itemgetter

users = [
{'fname': 'Buble', 'lname': 'Chew'},
{'fname': 'Ruby', 'lname': 'Red'},
{'fname': 'Red', 'lname': 'Baron'}
]

for x in sorted(users, key=itemgetter('fname')):
print(x)


for x in sorted (users, key=itemgetter('fname', 'lname')):
print(x)

cmxcvi.v
Автор

Does this code contains an 'Acqua' easterEgg? :D

xtruderD
Автор

what the ship! :D

anyway thanks for the videos mate :)

prasoonkd
Автор

Please how find last name of a person.
Conditions I know only first name of the person and I don’t know index

prithiviraj
Автор

I know to ship from poker. If you are about to win a poker tournament you are going to ship it. Or if you won, you can say "I shipped it"

jonathanwarner
Автор

this is the first time I heard of "ship"

maheepthephenom