No video

Python - List comprehension vs map function TUTORIAL (speed, lambda, history, examples)

  Рет қаралды 7,332

Brendan Metcalfe

Brendan Metcalfe

Күн бұрын

Python tutorial on the difference between the map() function and list comprehensions. We learn about using map with lambda and list comprehensions with lambda. We run speed test, compare advantages of each, and determine if you should use map or list comprehensions for iterating in Python. We also discuss what Guido prefers.
❗❗This video is part of a SERIES. Check out the other videos below ❗❗
💻 Python List Comprehensions Course Playlist:
• Ultimate Guide to Pyth...
💻 Python Interview Questions Playlist:
• Python Interview Quest...
📖 The complete Udemy course on Python Built-in Functions:
www.udemy.com/...
💻 Python filter() built-in function:
• Python 3 filter() buil...
💻 Python map() built-in function:
• Python 3 map() built-i...
💻 Python list() built-in function:
• Python 3 list() built-...
⚙️ Recommended Computer Gear:
- Macbook Pro 13" amzn.to/39ZGrTb
- Macbook screen protector amzn.to/3s2a9x3
- Macbook USB-C adapter amzn.to/3dRICtd
- Macbook case amzn.to/3wMJhVk
- Foldable computer stand amzn.to/2QeCi76
- Airpods amzn.to/324gPAs
- Pixel 3a amzn.to/2PJa1Wr
- Pixel 3a screen protector amzn.to/3mytvcf
- Lapel Mic amzn.to/39Vf2lx
- Bluelight computer glasses amzn.to/3dSCIId
- Noise cancelling headphones amzn.to/2QhAR80
- JBL bluetooth speaker amzn.to/3dVfLEv
✈️ Recommended Digital Nomad Gear:
- Shorts with zippers amzn.to/3wHEepf
- Silicone earplugs amzn.to/3wSSzQ3
- Sleep mask amzn.to/3d6AUw5
- Packing cubes amzn.to/3uCbaOc
- Sink plug amzn.to/2QeiSzf
- Travel lock amzn.to/3t2Zsf4
- Nike sandals amzn.to/3d65FRV
- Nike freeruns amzn.to/3fZRWhi
- Thin no-show socks amzn.to/39Wa8og
- Quest bars amzn.to/3s8eWxd
- Incense amzn.to/3dPfEKF
- Electronics organizer bag amzn.to/3tbn3KO

Пікірлер: 24
@ninesquared81
@ninesquared81 3 жыл бұрын
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.
@opium9202
@opium9202 8 ай бұрын
I thinks you should get more views. you are covering the most important topics and related questions. Thanks for the video
@mohammadjunaidmansoori9879
@mohammadjunaidmansoori9879 Жыл бұрын
May be this way num = [1, 2, 3, 4] lst = list(map(str, filter(lambda x: x > 1, num))) print(lst)
@brianglass8310
@brianglass8310 2 жыл бұрын
The history and best practices discussion was very helpful
@akira_asahi
@akira_asahi 2 жыл бұрын
Thank you for the video. I am grateful for your time and contribution. Kind regards, Akira.
@IntricateMoon
@IntricateMoon Жыл бұрын
THANK YOU FOR THIS BRENDAN!!!
@rb9888
@rb9888 7 ай бұрын
7:37 - it would be better to use filter first and then map ;-)
@Fine_Mouche
@Fine_Mouche 2 жыл бұрын
Ok, but how use the map without convert it ? which objects accept a map object ?
@Rocklee46v
@Rocklee46v 4 жыл бұрын
Great, you have explained everything.
@BrendanMetcalfe
@BrendanMetcalfe 4 жыл бұрын
Thanks!
@jell._.y
@jell._.y 4 ай бұрын
Lolol the creator not liking map, goated
@sehishok6664
@sehishok6664 3 жыл бұрын
Look man ..my English is weak but you have very nice way inserting information in brain... thank you
@BrendanMetcalfe
@BrendanMetcalfe 3 жыл бұрын
Thanks!
@yekhtiari
@yekhtiari 9 ай бұрын
I didn't get why you used map(int,[1,2,3,4]). The list was already int type.
@aviralsrivastava7197
@aviralsrivastava7197 4 жыл бұрын
great video!!!!
@gabrielamos9772
@gabrielamos9772 2 жыл бұрын
What editor are you using?
@BrendanMetcalfe
@BrendanMetcalfe 2 жыл бұрын
VS Code, Screenflow
@Morexod999
@Morexod999 2 жыл бұрын
Hello! What is this editor\high-lighting software? It looks cool
@BrendanMetcalfe
@BrendanMetcalfe 2 жыл бұрын
Bpython
@OldOne.OO1
@OldOne.OO1 3 жыл бұрын
تستاهل الف لايك ...شكرا من 💔
@BrendanMetcalfe
@BrendanMetcalfe 3 жыл бұрын
شكرا جزيلا
@kingmoon989
@kingmoon989 3 жыл бұрын
استمر ياوحش
@scott9503
@scott9503 3 жыл бұрын
you sound like casually explained
@BrendanMetcalfe
@BrendanMetcalfe 3 жыл бұрын
haha never heard that
List comprehension vs filter in Python (speed, lambda, history, examples)
16:18
List comprehension vs reduce in Python (What happened to reduce?)
10:22
Brendan Metcalfe
Рет қаралды 1,6 М.
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН
لقد سرقت حلوى القطن بشكل خفي لأصنع مصاصة🤫😎
00:33
Cool Tool SHORTS Arabic
Рет қаралды 30 МЛН
Why Is He Unhappy…?
00:26
Alan Chikin Chow
Рет қаралды 92 МЛН
Dictionary Comprehension - Create Complex Data Structures Step by Step
21:58
How Audio Illusions Trick Our Brains
24:55
Veritasium
Рет қаралды 84 М.
Python: Lambda, Map, Filter, Reduce Functions
9:59
Oggi AI - Artificial Intelligence Today
Рет қаралды 379 М.
List Comprehension - BEST Python feature !!! Fast and Efficient
14:51
Python Simplified
Рет қаралды 191 М.
Decision Tree from scratch using numpy.
24:28
prynshus
Рет қаралды 83
Каха заблудился в горах
00:57
К-Media
Рет қаралды 10 МЛН