Python Dictionary Tip!! #python #coding #programming

Python Dictionary Tip!! #python #coding #programming

b001

1 год назад

85,225 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

AussieFullFatRangeRover
AussieFullFatRangeRover - 19.08.2023 06:17

Thank you!!

Ответить
Budgiedeep21
Budgiedeep21 - 24.07.2023 02:06

This is helpful as there are examples 🎉

Ответить
Harry Stewart
Harry Stewart - 29.05.2023 15:50

Is there a way to do this in c#

Ответить
Igor Schreiber
Igor Schreiber - 27.05.2023 03:12

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.

Ответить
SublianDev
SublianDev - 24.05.2023 21:40

Good short

Ответить
alfred muñoz
alfred muñoz - 31.03.2023 01:41

Like NVL()

Ответить
Johnny
Johnny - 19.03.2023 23:56

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.

Ответить
Ivanok kekes
Ivanok kekes - 19.03.2023 23:07

Love it

Ответить
Ikenna Nicholas Ikwuka
Ikenna Nicholas Ikwuka - 19.03.2023 12:17

what theme do you use

Ответить
Pantan LP
Pantan LP - 19.03.2023 03:12

Orrrrrrrr every player gets a default value assigned cause you normally cant afford having a messy database

Ответить
Louis Tiches
Louis Tiches - 16.03.2023 20:25

Lol, lose with the word database. A list of variable names that are dicts.

Ответить
Biscuit
Biscuit - 02.03.2023 15:47

Im pretty sure its called get or default

Ответить
Darkev
Darkev - 01.03.2023 09:33

When would you ever use dic[key] over dic.get(key)

Ответить
LaxLyfters
LaxLyfters - 19.02.2023 09:18

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

Ответить
Fabio Gaming
Fabio Gaming - 15.02.2023 14:33

Python developers have discovered dictionary functions
Phenomenal

Ответить
Rodrigo Araya
Rodrigo Araya - 12.02.2023 03:32

Hello don't understand this...

Ответить
CreateSource
CreateSource - 04.02.2023 17:39

Couldnt you just make the line p['level'] or 0? Does .get() do something special?

Ответить
Topsoil Depletion Awareness (closing the loop)
Topsoil Depletion Awareness (closing the loop) - 04.02.2023 08:20

The future of coding is here. Every time u type code a meme pop out.

Ответить
aggi999
aggi999 - 02.02.2023 16:38

Or simply do if 'level' in p.keys()

Ответить
Nando Lopez
Nando Lopez - 02.02.2023 05:37

Entendi tudo

Ответить
Kakak Akaka
Kakak Akaka - 02.02.2023 02:13

Good stuff

Ответить
Clips To Binge On
Clips To Binge On - 02.02.2023 01:15

Wwoooo

Ответить
Alex T
Alex T - 01.02.2023 19:31

Working with non strict data types. Tisk tisk

Ответить
kamran view
kamran view - 01.02.2023 16:33

please more videos abouts pandas and hoe its work full video start to ends please brooooo

Ответить
Varun Reddy M
Varun Reddy M - 01.02.2023 00:47

Hey, @b001 can you make a video on how to setup vs code for python?

Ответить
Elliot Phoenix
Elliot Phoenix - 31.01.2023 23:54

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

Ответить
naná santos
naná santos - 31.01.2023 23:34

Very useful, thanks

Ответить
DJcrafter
DJcrafter - 31.01.2023 19:47

Name of the music plz?

Ответить
Naren
Naren - 31.01.2023 12:22

Great need more

Ответить
jumper0122
jumper0122 - 31.01.2023 10:27

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.

Ответить
kuroi san
kuroi san - 31.01.2023 10:22

what is your theme name ?

Ответить
Peace
Peace - 31.01.2023 08:32

Cool

Ответить
Randych
Randych - 31.01.2023 08:29

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

Ответить
Josué Estrada
Josué Estrada - 31.01.2023 07:52

Every short I find I put it in a good-to-know list. Great info!!

Ответить
Kriton Iordanidis
Kriton Iordanidis - 31.01.2023 07:46

Nice! What theme do you use in VSCode?

Ответить
Amatsu
Amatsu - 31.01.2023 06:35

Noice

Ответить
TheMineCommander
TheMineCommander - 31.01.2023 02:41

This is one of the ones that I think I'll actually be using! Thank you!

Ответить
Sharpsrain
Sharpsrain - 31.01.2023 02:32

Ayeee keep it up mang

Ответить
Tor Shepherd
Tor Shepherd - 31.01.2023 02:30

If you want that default to be inserted into the dictionary instead, you could use a defaultdict

Ответить