Not necessarily, assume you have a list of unknown values whose types are not necessarily strings. This more general approach considers the 'str' representation of the object...Python is very intelligent (even if slow! Python has this important tradeoff!).
Yes it is, upper is a string function. The function does not exist for types like numbers, for example. If you are unsure of the type, you'd do str(string).upper() Wrapping that expression with colons is irrelevant. An exception will be raised before that if string is for example an int as upper() is only defined for string types
@@Andrumen01You're wrong, for two reasons: the type annotations indicate that these are strings, and `.upper()` is a method of the `str` class. Also, the code in the video is converting the string in uppercase to a string, so the f-string here is useless.
@@davidmurphy563 Really? I introduce you to statically typed languages, then, even "worst", you're forced to put the complete type for each variable declaration!
@Dimitrius1991 Not really, it's always near the variable's name. Also it's more readable `var: Type = val` as "`var` of type `Type` which is equal to `val`", instead of `Type var = val;` that you or have to reverse the order of the type and the name, or have to say it in an unusual order: "a variable of type `Type` named `var` which is equal to `val`". But at the end, it's you that chose.
@foxypiratecove37350 I mean, it's more readable when a declaration and the corresponding assignment are not in the same line, especially if the type name is long. Also, I've had enough of static typing already.😆
defaultdict mentioned!! 🔊🔊🔊
dict.setdefault: «am I a joke to you?»
that's a different default.
except at 6:15 where it is probably preferable.
I never thought I would hear Indently saying "yo mamma"
defaultdict is so useful, I've gotten annoyed at some other languages when their version of a dictionary didn't have an equivalent.
what default function do you use? And don't say "int".
4:41 Isn't the f-string overkill here?
Not necessarily, assume you have a list of unknown values whose types are not necessarily strings. This more general approach considers the 'str' representation of the object...Python is very intelligent (even if slow! Python has this important tradeoff!).
Yes it is, upper is a string function. The function does not exist for types like numbers, for example. If you are unsure of the type, you'd do str(string).upper()
Wrapping that expression with colons is irrelevant. An exception will be raised before that if string is for example an int as upper() is only defined for string types
@@Andrumen01You're wrong, for two reasons: the type annotations indicate that these are strings, and `.upper()` is a method of the `str` class. Also, the code in the video is converting the string in uppercase to a string, so the f-string here is useless.
Isn't using a defaultdict overkill in the string example? A normal dict would already work. Bad example...
@korntut I honestly don't know, I'm not a `defaultdict` expert. But yeah it seem a bit overkill, but the f-string was more obvious.
If you try to access a key without adding it to this dictionary, is that key implicitly added (with the default value) or not?
Yes
Great video. Thanks
Calamansi (whatever that is - even spell checked did not know it) example works very well with dict() instead of defaultdict()
C'est horrible la voix IA dégueu pour le doublage
Je vais essayer à l’écouter quand je rentre chez moi. Je suis très curieux!
La voix originale est bien mieux
who is this diva
5:00
dict(zip(los, map(str.upper, los))
is mo' better.
{string: string.upper() for string in list_of_strings}
😰
Ugh!: interjection All: pronoun these: adverb types: noun make: verb it: pronoun so: adverb hard: adverb to: particle read: verb
@@davidmurphy563 Really? I introduce you to statically typed languages, then, even "worst", you're forced to put the complete type for each variable declaration!
@foxypiratecove37350 In that case type declarations are usually separate and don't harm readability.
@Dimitrius1991 Not really, it's always near the variable's name. Also it's more readable `var: Type = val` as "`var` of type `Type` which is equal to `val`", instead of `Type var = val;` that you or have to reverse the order of the type and the name, or have to say it in an unusual order: "a variable of type `Type` named `var` which is equal to `val`". But at the end, it's you that chose.
@foxypiratecove37350 I mean, it's more readable when a declaration and the corresponding assignment are not in the same line, especially if the type name is long. Also, I've had enough of static typing already.😆