Python Mapping?? #python #programming #coding

preview_player
Показать описание
This video shows you how to use Python's built in map() function to apply a function to each element of an iterable.

Background Music:
Creative Commons Attribution 3.0 Unported License
Рекомендации по теме
Комментарии
Автор

In my opinion, you should only use the map object if you're not converting it to a different datatype. For this, [tax(citizen) for citizen in citizens] is nicer

schlopping
Автор

What if I'd have told you that you can replace all of your code by one line ...
taxed_citizens = map(lambda c: (c[0], c[1]*0.93), citizens)

dud
Автор

I would do it like this:
[tax(c) for c in citizens]

amogid
Автор

if you just do simple modifications, do it in one line using list comprehension:
taxed_citizens = [(name, money*0.93) for name, money in citizens]

caas
Автор

Not only is this better, using the map function instead of the for loop is faster. Making your code more efficient.

wbprosario
Автор

Love these names. Your code is so clean it almost like reading kings English.

rileyschenk
Автор

Holy shit. I’m not a professional programmer but I needed this earlier, I’m still gonna use it but thank you so much

someguy
Автор

I would have used a list comprehension. taxed = [tax(citizen) for citizen in citizens]

knut-olaihelgesen
Автор

Prefer list comprehensions. Just call tax on each iteration in the list comprehension.

arkster
Автор

I dropped a like but I also want to drop a comment to make the algorithm favor your shorts other than some regurgitated tiktok dance video that's been reposted five million times

terryfries
Автор

taxed_citizens = [(x, y * 0.93) for x, y in citizens]

TheRealisticNihilist
Автор

You can also make the whole function into a lambda

justsomeduckwithacap
Автор

I really thought you were going to use a list comprehension, which is how I would have done this, but after seeing this I think using the map() function is probably a better idea

QuotePilgrim
Автор

I don't speak Python or any other language yet I love these shorts.

helmanfrow
Автор

this is a situation for comprehensions

aonodensetsu
Автор

Or list comperhension, if you want a list anyway:
taxes=[tax(citizen) for citizen in citizens]

oida
Автор

taxed_citizens = [tax(citizen) for citizen in citizens] works too

drip
Автор

Please tell me what theme you are using.

barbellbilly
Автор

And the map is even faster than the regular loop!

hugo-onzakorderra
Автор

What mic are you using? And can you share your video creation process please?

codecompass