I think one time to use map over a list comprehension is when you don't actually need a list. For example, I have a function that takes 24 hour time as a string and converts it to the number of minutes from 00:00 for that time. The way my function works is to unpack the 24 hour time into two variables hrs and mins which are integers. Using map (as I have done): def minutes(str_time): hrs, mins = map(int, str_time.split(':')) return hrs*60 + mins Using list comprehension: def minutes(str_time): hrs, mins = [int(x) for x in str_time.split(':')] return hrs*60 + mins To me, use of map here is more intuitive and probably faster, although speed isn't really my concern here. This is my first time using map since I started to learn Python in February 2020. If I want a list I'll of course use list comprehension because it is generally clearer and doesn't require calling the list function.
@mythuszeus I haven't really used anything higher level than Python. I have tried Haskell a couple of times but never really got anywhere with it. I have gone the other way, though, with C and a little assembly. My current project is a programming language compiler, written in C, and with x86 assembly as the output.
I thinks you should get more views. you are covering the most important topics and related questions. Thanks for the video
I think one time to use map over a list comprehension is when you don't actually need a list.
For example, I have a function that takes 24 hour time as a string and converts it to the number of minutes from 00:00 for that time.
The way my function works is to unpack the 24 hour time into two variables hrs and mins which are integers.
Using map (as I have done):
def minutes(str_time):
hrs, mins = map(int, str_time.split(':'))
return hrs*60 + mins
Using list comprehension:
def minutes(str_time):
hrs, mins = [int(x) for x in str_time.split(':')]
return hrs*60 + mins
To me, use of map here is more intuitive and probably faster, although speed isn't really my concern here.
This is my first time using map since I started to learn Python in February 2020.
If I want a list I'll of course use list comprehension because it is generally clearer and doesn't require calling the list function.
Year 2024. I wonder how much you've learned about python, most probably advanced to some higher level languages?
@mythuszeus I haven't really used anything higher level than Python. I have tried Haskell a couple of times but never really got anywhere with it.
I have gone the other way, though, with C and a little assembly. My current project is a programming language compiler, written in C, and with x86 assembly as the output.
THANK YOU FOR THIS BRENDAN!!!
The history and best practices discussion was very helpful
May be this way
num = [1, 2, 3, 4]
lst = list(map(str, filter(lambda x: x > 1, num)))
print(lst)
Nice!
What editor are you using?
VS Code, Screenflow
Hello! What is this editor\high-lighting software? It looks cool
Bpython
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
Ok, but how use the map without convert it ? which objects accept a map object ?
7:37 - it would be better to use filter first and then map ;-)
Lolol the creator not liking map, goated
Great, you have explained everything.
Thanks!
great video!!!!
I didn't get why you used map(int,[1,2,3,4]). The list was already int type.
Thanks!
Look man ..my English is weak but you have very nice way inserting information in brain... thank you
Thanks!
تستاهل الف لايك ...شكرا من 💔
شكرا جزيلا
استمر ياوحش
you sound like casually explained
haha never heard that