Python : How to add multiple values to a dictionary key

preview_player
Показать описание
👍 99% of viewers don't show their love! Leave a like to support us!

Datacamp

Get $20 discount click the link.

Python dictionary is an unordered collection of items. While other compound data types have only value as an element, a dictionary has a key: value pair. Dictionaries are optimized to retrieve values when the key is known.

subscribe for more videos


If you really enjoy my content, you're welcome to support me and my channel with a small donation via PayPal.

Link to PayPal donation


Follow on Twitter

Follow on Facebook


#joanapita
Рекомендации по теме
Комментарии
Автор

to all the idiots who disliked to adda value to a dictionary jnot in same line uise .add

oussematoussli
Автор

Thank you bro for quick short informational video.

AnilKumar-xwjb
Автор

can you do a video how to set values in a dictionarys at a later time ? Is there any set or get methods like in c++ for that ?

yc
Автор

l = list(map(str, input().split(', ')))
d = {}
d = {l[i+1].upper() : (int(l[i]) if l[i+1] not in d else d[l[i+1]]+int(l[i])) for i in range(0, len(l), 2)}
print(d)
#input : 101, p, 102, o, 302, p, 305, p

sir, please tell me how to add value to the existing key of the dictionary in one line, in the above code value is updating to a key but it is not adding can you solve it for me, please.

annahari