Python Programming Tutorial - 20 - Dictionary

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

you should be teaching about placeholders so people get in the habit of using them and not having to worry about remembering spaces while printing variables

classmates = {'tony':'cool but smells', 'emma':'sits behind me', 'lucy':'asks too many questions'}

for k, v in classmates.items():
    print('{} {}'.format(k, v))


instead of just printing k + v you use {} in place  of each variable and can place the space in between. you just have to follow the closing ' with .format(each var that will fill the placeholders)

just a thought. good tutorials

chetkauffman
Автор

These are fast, fun, entertaining, and informative. Can't thank you enough!

GAment_
Автор

awesome
people={'ivan':10, 'anton':15, 'ivana':24, 'joso':23}

for k, v in people.items():
if v<18:
print(k, "is child")
else:
print(k, "is adult")

domagojradicevic
Автор

I like watching Bucky's videos while high on my sleep meds at night while on my painkillers. its interesting

stonedgamer
Автор

Hey NewBoston...
I have recently started working with python.. and your tutorials are big help..

just sharing something I tried myself, instead of using 'k' and 'v', keeping the motive same as printing them.. I used below code.. which worked in the similar manner -

classmate = {'Tony':'he is good guy', 'Nandi':'she is lazy', 'Ram':'he is studious', 'Mike':'he sleeps alot'}
print(classmate)

for c in classmate:
print(classmate[c])

#this for loop give same output as we get using k and v... also noticed few comments where people speaking about sorting order.. well mine was not sorted and it was printed in the order they were declared.

soumyait
Автор

print(k, v) will also work, and it doesnt require to add any white spaces to your strings

atulchavan
Автор

In Lua we call these "tables". And they're a crucial concept to understand.

luaentertainment
Автор

Cool thing how you pointed out the keys and values. Got more "visual" and logic.

dannymorckjensen
Автор

For the loops part you don't need to put + between the variable just a comma then dont need to do the spacing

jeffarias
Автор

Age = {'Noboni': '13', 'Ziad': '17', 'Affan': '7', 'Bithi': '28', 'Sazib': '40'}

for k, v in Age.items():
v=int(v)
if v>= 50:
print(k + ' is senior')
elif v >= 18:
print(k + ' is adult')
elif v >=10:
print(k + ' is kid')
else:
print(k + ' is child')

syedmishkatulhaque
Автор

Can we please have a clear and concise explanation why the '.items' is used after classmates? Bucky doesn't mention it and it is not at all intuitive to a beginner. This is the first time this scripting technique has been used in this tutorial series, and this is a tutorial for *beginners*

hanniballecter
Автор

in what order is it printed
i can't see any logic behind it.. LIFO of FIFO ?

elecktromaestimmy
Автор

why did it print out lucy first while tony was first?

roemerblom
Автор

it works better if you write
print(k, v) instead of print (k+v)

syedmishkatulhaque
Автор

Just wandering can you unpack dictionaries? like def Checkmate(*Classmates). How would that work? Would it like put the value or the key?

maxguichard
Автор

Hello! I don't understand in the for loop why you have to add .item() to classmates so classmates.item().
If you just leave it at For k, v in classmates is that not enough??

yameischeda
Автор

took me a month to learn all these List APIs and File writing in Java, took me less than an hour in python

rajshah
Автор

I appreciate all the effort you put into these videos. Thank you very much, it was really helpful. I have a question about numpy. How can i use numpy in my eclipse, i downloaded it but i dont know how to set it up in eclipse. Thanks for any help

expeditionquran
Автор

a little confused by the use of {} when creating the dictionary, and [] when adding searching a specific key in the dictionary, and why () does not work.

eg:
classmates = {'tony':'cool but smells', 'mark':'cool but loud', 'lucy':'probably a vs. print(classmates['mark']) vs. print(classmates('mark'))

anyone able to explain this?

agxryt
Автор

so is the key is x=key[] 32 bit quantum core value in python that returns hydrogen C3 bits when executed in DNA Mode or quantum core files with data type that supports ecommerse values for stock?

shaanbeentv
visit shbcf.ru