Тёмный

ALL 11 Dictionary Methods In Python EXPLAINED 

Indently
Подписаться 197 тыс.
Просмотров 56 тыс.
50% 1

All 11 dictionary methods in Python explained. Did you know all of them?
▶ Become job-ready with Python:
www.indently.io
▶ Follow me on Instagram:
/ indentlyreels
00:00 11 Dict Methods
00:07 values()
00:35 keys()
00:54 pop()
01:42 popitem()
02:15 copy()
03:45 get()
04:42 setdefault()
05:40 clear()
06:00 fromkeys()
06:57 items()
07:33 update()
09:09 Conclusion

Опубликовано:

 

17 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 73   
@datint0003
@datint0003 11 месяцев назад
God, I love dictionaries in python
@hackerviber
@hackerviber 6 месяцев назад
What are you doing bro in this time
@davidyoung623
@davidyoung623 11 месяцев назад
You can specify a default value for pop as well, to avoid the KeyError: pop(key, default)
@Indently
@Indently 11 месяцев назад
Thanks for sharing, I completely missed that!
@miguelvasquez9849
@miguelvasquez9849 11 месяцев назад
you should place the pop in an except code block
@davidyoung623
@davidyoung623 11 месяцев назад
@@miguelvasquez9849 That depends on if you want to catch an error, or avoid the error in the first place 😉
@mienislav
@mienislav 4 месяца назад
3 years programming in Python. Almost all my implementations in for loop were just like if key in d.keys(): d[key] = ["value"] else: d[key].append("value") Where each search for key is O(n). If only I had known about fromkeys() before! That would simplify my code to complexity O(n) on the creation and just O(1) for searching and updating, like that: keys = ("abc", "def") d = d.fromkeys(keys, []) d["abc"].append("value") Thank you very much for this video! This was very helpful!
@rantalbott6963
@rantalbott6963 11 месяцев назад
Thank you. As always with your stuff, this is a great "Introduction to...": complete, but succinct and clear. And nicely indexed so people can skip over methods they're already familiar with. Since you asked ... I'm still fairly new to Python, so there were a couple I'd never heard of, and a few that I'd *only* heard of and never learned. I'll definitely be using a few more them now that you've introduced me.
@airslav
@airslav 20 дней назад
thanks a lot for the tutorial👍 I find it very informative but it's still hard for me to work with dictionaries
@davidznidarsic5497
@davidznidarsic5497 11 месяцев назад
Great channel, learned about you via Shorts... Re: popitem: (a) popitem removes the *last* item, but the last item is defined by the last item inserted in the dict. The example in the video uses items that happen to be in numerical order by key. Such an example could give the impression that popitem will always remove the key with the largest value; however, if the example was users: dict = {0: 'Mario', 2: 'James', 1: 'Luigi'}, popitem would remove the last item entered, which is 1: 'Luigi'; (b) prior to Python 3.7, popitem removed a *random* item, because only in 3.7+ were the order of dict items preserved by their order of entry.
@davidznidarsic5497
@davidznidarsic5497 11 месяцев назад
I should have said: prior to Python 3.7, popitem removed some unspecified item based on the implementation details of the Python runtime; that is, not to imply that popitem was a clever way to remove a random item.
@peterbarasa9190
@peterbarasa9190 11 месяцев назад
What is the difference between .items() and .__dict__() method?
@KrishnaManohar8021
@KrishnaManohar8021 11 месяцев назад
Can you come up with Data Structures and Algorithms?
@CaseyFahey
@CaseyFahey 11 месяцев назад
... and design patterns 👍
@Indently
@Indently 11 месяцев назад
There’s a professional who covers this in great detail with years of experience. Check out: Arjan Codes
@CaseyFahey
@CaseyFahey 11 месяцев назад
@@Indently Great recommendation, excellent content as is your own, thank you 🙏
@Sinke_100
@Sinke_100 11 месяцев назад
Great one man, I knew every of those, but very helpfull informational video
@marcincuprjak1005
@marcincuprjak1005 11 месяцев назад
Perhaps worth adding: the del operation to remove item without returning the value. In your example dict it would be: del users[2]
@harishvengat1465
@harishvengat1465 11 месяцев назад
Bro, have you heard about the flet framework (flutter for python), can you create an playlist that goes through all basic and intermediate level contents , please, because I tried searching tutorials for flet but didn't get what I wanted, and sorry if I said anything bad, bcoz English is not my mother tongue
@Indently
@Indently 11 месяцев назад
flet looks awesome! I will look into it :)
@harishvengat1465
@harishvengat1465 11 месяцев назад
@@Indently thanks bro 🥰
@watchmakerful
@watchmakerful 2 месяца назад
Is it possible to find an intersection of dictionaries, i. e. the keys common in both ones?
@johnniegilkerson4724
@johnniegilkerson4724 Месяц назад
Are you using the colon instead of an equals sign?
@im_jst_tired4280
@im_jst_tired4280 4 месяца назад
finally learned how to use dictionaries (been a computer science major for 2 years)
@KinkyJalepeno
@KinkyJalepeno Месяц назад
Fantastic vid - much appreciated
@user-fl2hh1oe8n
@user-fl2hh1oe8n 4 месяца назад
what IDE you use ? yours look minimilistic.
@louie0187
@louie0187 5 месяцев назад
I think you glossed over setdefault. setdefault is useful when initializing a dict(). it returns the newly created key/val pair, and you can modify if right there.: mydict[key]=mydict.setdefault(key,0)+=1 or mydict[key]=mydict.setdefault(key,[]).append(val) .setdefault closer to behavior you get with defaultdict then comparing to get()
@robertkelleher1850
@robertkelleher1850 4 месяца назад
Pretty good list. You did miss that pop has a default parameter available. Maybe it's a cultural thing, but the character "|" is just called pipe, not pipeline.
@PestOnYT
@PestOnYT 5 месяцев назад
I'd lioke to add that popitem() is like item(), but removes the pair from the dict. So, you can use the key/value pair in a loop and (may) have an empty dict after that.
@glgeorgiou
@glgeorgiou 8 месяцев назад
Very interesting. The method 'fromkeys' did not work as expected and produced a sytax error. The code --------------- people: list[str] = ['Mario', 'Luigi', 'James'] users: dict = dict.fromkeys(people, __value:'Uknown') print(users) -------------- The error has to do with the use of ':'.
@nathancalkins3902
@nathancalkins3902 11 месяцев назад
I made a dictionary to try to make a program that helps me with learning French. It is formatted like this, Vocab = { "manger": { "translation": "to eat" "conjugations": { "je" : "mange", "tu" : "mange", ect.... I am trying to make it asks me the translation of a random word first if I get to right it says correct, wrong it says incorrect and shows me the fight translation. followed by each of the conjugations separately either saying correct or showing me the answer if incorrect. How would I go about starting that? New to python
@theory5810
@theory5810 11 месяцев назад
It would be nice to know the average time complexity of these methods.
@danisimus1517
@danisimus1517 11 месяцев назад
i think its look like this: 0.000000000000000000000000000000000000
@benlong1062
@benlong1062 11 месяцев назад
Great video, Thank you!
@debbrondatesfoods7734
@debbrondatesfoods7734 8 месяцев назад
I was just curious.....why did you remove the names when you used the dict.copy() method?
@bulldawg4498
@bulldawg4498 11 месяцев назад
Educational and instructive ...
@Lanc840930
@Lanc840930 11 месяцев назад
Very useful. Thanks
@ArgentinaInstrumental
@ArgentinaInstrumental 10 месяцев назад
It got me thinking. Since when Python started adding linux-like syntax in it? The match-case syntax also comes from bash scripting, so there is anything else on that avenue that was added recently?
@SusanAmberBruce
@SusanAmberBruce 4 месяца назад
I learned something new, |= thanks
@supa.scoopa
@supa.scoopa 6 месяцев назад
What colour theme are you using? Thank you!
@hackerviber
@hackerviber 6 месяцев назад
Use extansiion
@xlerb_again_to_music7908
@xlerb_again_to_music7908 11 месяцев назад
Hmm... the key order. What makes them come out in sequence?? Or, is that built into print?
@MilChamp1
@MilChamp1 11 месяцев назад
the keys are in insert order. This was implemented in Python 3.
@paulw4259
@paulw4259 7 месяцев назад
Thank you.
@yasink18
@yasink18 11 месяцев назад
I have one question.. Why we can't use dictionary or list in key.. But can use tuple or set in dictionary keys
@JeremyLangdon1
@JeremyLangdon1 11 месяцев назад
Lists and dictionaries are mutable, meaning they can be changed after they are created, which makes them unhashable and therefore unsuitable for use as dictionary keys. Tuples and sets are immutable (well, technically sets are mutable, but "frozen sets" are not), meaning their contents cannot be changed after they are created, making them hashable and suitable for use as dictionary keys.
@rgAlex8386
@rgAlex8386 8 месяцев назад
Good tuto bro
@borneoviral6379
@borneoviral6379 11 месяцев назад
great video
@throwyourmindat
@throwyourmindat 11 месяцев назад
Hi Are you aware of self healing selenium scripts? Can you explain the concept of self healing and how is it even possible!? Because we find element on web page using a locator if that element isn't found we get error. How can self healing find that locator. For eg. An element found by //input[@name=email] if not found, can automatically guess the element was updated in next build as //input[@name=mailing-addrress] using self healing approach.. it would be great if you can help us understand that
@Indently
@Indently 11 месяцев назад
The concept is that if your code fails, other code will fix that code so it will work. ChatGPT is being used for this recently.
@throwyourmindat
@throwyourmindat 11 месяцев назад
@@Indently but I saw few videos where people have already created such code in Java.. before chatgpt was released.. but none shared their code.. neither their explanation was proper so I was wondering how they managed..
@KnightAmine
@KnightAmine 11 месяцев назад
I thought the dictionary is not sorted so there should not be a last item. Is it like random?
@RosesSRC
@RosesSRC 11 месяцев назад
Since Python 3.7 dictionaries are ordered, which means the order in which the key-value pairs are entered are the order like in a list. Hence the .pop() method will "pop" the last item added to the dictionary.
@balazsszalai41
@balazsszalai41 11 месяцев назад
I think it would have been useful to also include the __getitem__ method of the dictionaries.
@no_the_other_ariksquad
@no_the_other_ariksquad 11 месяцев назад
Isn't that just the [0] for example? Or I think it is that.
@balazsszalai41
@balazsszalai41 11 месяцев назад
@@no_the_other_ariksquad It is but that is also a method and is also useful because you can get the value corresponding to the key, you can change the value of an existing key value pair and you can append a new key value to the dictionary and in many cases it feels cleaner to me personally that the other methods where you don't need the specialized functionality of the other dictionary methods (for example returning a default value if the key doesn't exist).
@Indently
@Indently 11 месяцев назад
Sounds like you need to write a fair bit of documentation for anyone that uses your special “__getitem__ implementation. I’m not saying you should avoid it, but at least every developer knows immediately what’s going on with get() and setdefault(). I might make a video about getitem regardless, thanks for the suggestions :)
@zurgmuckerberg
@zurgmuckerberg Месяц назад
I love dicts!
@juanrojas4239
@juanrojas4239 11 месяцев назад
Thanks god, thanks
@kvelez
@kvelez 9 месяцев назад
users : dict = {0:"Mario", 1:"Luigi", 2:"James"} popped : str = users.pop(2) popitems : str = users.popitem() print(users) copied : dict = users.copy() copied[0] = "!!!" print(copied) sample_dict: dict = {0: ['a', 'b'], 1:['c',"d"]} my_copy : dict = sample_dict.copy() my_copy[0][0] = "???" print(my_copy) print(users.get(0)) print(users.get(3, "Not found")) print(users.setdefault(4, "Brownstone")) copied.clear() people: list[str] = ["Mario", "Luigi", "James"] users: dict = dict.fromkeys(people) print(users) users.items() users.values() users.keys() users.update({4:"Bob"}) print(users)
@dfields9511
@dfields9511 19 дней назад
cool |= cool
@afonsopalmeira6951
@afonsopalmeira6951 7 месяцев назад
Hello everyone is anyone called Mulher brava here ?
@krzysiekkrzysiek9059
@krzysiekkrzysiek9059 11 месяцев назад
Dude I appreciate your channel a lot, because I learned a lot, but marking the type of simple global variables is annoying and demolishes the concept of a dynamically typed language. I can understand in classes or functions to make them easier to use, but in simple obvious variables?
@Indently
@Indently 11 месяцев назад
Some people call it consistency.
@krzysiekkrzysiek9059
@krzysiekkrzysiek9059 11 месяцев назад
@@Indently Yeah, consistency is very proper and professional, but this one looks like overused Federico. This is such a subjective opinion of mine, besides, I am waiting for another valuable content.
@Indently
@Indently 11 месяцев назад
For me it helps, because when I make special rules I tend to forget where it actually matters. And it doesn't hurt readability, especially for someone who got so used to seeing them, it hurts me more to not see them, regardless of how obvious the variables might be. But at the end of the day, they are optional, so my coding style of being extra explicit can only benefit those who choose to be less explicit.
@user-ou7hd1zi2i
@user-ou7hd1zi2i 5 месяцев назад
Watch out leetcode! Your end is nigh!
@mouhamedtanfouri3666
@mouhamedtanfouri3666 5 месяцев назад
barri nayki bil pub
Далее
ALL Code Editors NEED THIS Feature (Inlay Hints)
3:50
20 Everyday Tips & Tricks in Python
25:18
Просмотров 21 тыс.
Running With Bigger And Bigger Feastables
00:17
Просмотров 80 млн
5 Good Python Habits
17:35
Просмотров 491 тыс.
Python dictionaries are easy 📙
8:06
Просмотров 216 тыс.
Naming Things in Code
7:25
Просмотров 2,1 млн
How To Use List Comprehension In Python
6:41
Просмотров 7 тыс.
5 Really Cool Python Functions
19:58
Просмотров 60 тыс.
Please Master These 10 Python Functions…
22:17
Просмотров 130 тыс.
10 Nooby Mistakes Devs Often Make In Python
24:31
Просмотров 58 тыс.
5 Tips To Write Better Python Functions
15:59
Просмотров 101 тыс.
Python lists, sets, and tuples explained 🍍
15:06
Просмотров 258 тыс.