Комментарии:
Thank you!!
ОтветитьThis is helpful as there are examples 🎉
ОтветитьIs there a way to do this in c#
ОтветитьIn Java we extend the class and implement extra method get with conditional to check if key exists and return default value if not. In python you just have it implemented already.
ОтветитьGood short
ОтветитьLike NVL()
ОтветитьBetter practise to my knowledge would be having a Players class that wraps all the relevant information, and then just a list of classes.
Another option would also be importing defaultdict.
Love it
Ответитьwhat theme do you use
ОтветитьOrrrrrrrr every player gets a default value assigned cause you normally cant afford having a messy database
ОтветитьLol, lose with the word database. A list of variable names that are dicts.
ОтветитьIm pretty sure its called get or default
ОтветитьWhen would you ever use dic[key] over dic.get(key)
ОтветитьThis is amazing for getting values in fetch request and accounting for empty values. In the pokemon api there are some pokemon that have many types and I was unable to render both types since I would get an error if the second type value was empty now I can assign it an empty string
ОтветитьPython developers have discovered dictionary functions
Phenomenal
Hello don't understand this...
ОтветитьCouldnt you just make the line p['level'] or 0? Does .get() do something special?
ОтветитьThe future of coding is here. Every time u type code a meme pop out.
ОтветитьOr simply do if 'level' in p.keys()
ОтветитьEntendi tudo
ОтветитьGood stuff
ОтветитьWwoooo
ОтветитьWorking with non strict data types. Tisk tisk
Ответитьplease more videos abouts pandas and hoe its work full video start to ends please brooooo
ОтветитьHey, @b001 can you make a video on how to setup vs code for python?
ОтветитьCan't python ignore KeyError if you use 'or' keyword?
Is this work in Python?:
level = player['level'] or 0
Becuse you can do this in php with nullsafe (??):
$level = $player['level'] ?? 0;
Or JS with 'or' operator:
let level= player['level'] || 0
Very useful, thanks
ОтветитьName of the music plz?
ОтветитьGreat need more
ОтветитьMy favorite way to use this is to return an empty dictionary for the default value. This way you can traverse huge nested dictionaries really easily. For instance, a school curriculum with Course, Section, Class Number that contains a list of required textbooks:
books = curriculum.get("DDSN", {}).get("101", {}).get("001", [])
This returns a list whether or not the class "DDSN 101-001" exists. With much more complex dictionaries this can be incredibly useful.
what is your theme name ?
ОтветитьCool
ОтветитьThis is dumb and ugly.
If you have anything more complex than just this, say 10-20 kv pairs, instead of assinging default values "at birth" you'll have to rely on idiotic defaulting which can cost you a lot of headache of "where tf this coming from".
This is one of reasons I quite hate python
Every short I find I put it in a good-to-know list. Great info!!
ОтветитьNice! What theme do you use in VSCode?
ОтветитьNoice
ОтветитьThis is one of the ones that I think I'll actually be using! Thank you!
ОтветитьAyeee keep it up mang
ОтветитьIf you want that default to be inserted into the dictionary instead, you could use a defaultdict
Ответить