Learn Python list comprehensions 📃
Vložit
- čas přidán 1. 06. 2024
- List comprehension = A concise way to create lists in Python
Compact and easier to read than traditional loops
[expression for value in iterable if condition]
doubles = [x * 2 for x in range(1, 11)]
triples = [y * 3 for y in range(1, 11)]
squares = [z * z for z in range(1, 11)]
fruits = ["apple", "orange", "banana", "coconut"]
uppercase_words = [fruit.upper() for fruit in fruits]
fruit_chars = [fruit[0] for fruit in fruits]
# List comprehension = A concise way to create lists in Python
# Compact and easier to read than traditional loops
# [expression for value in iterable if condition]
doubles = [x * 2 for x in range(1, 11)]
triples = [y * 3 for y in range(1, 11)]
squares = [z * z for z in range(1, 11)]
fruits = ["apple", "orange", "banana", "coconut"]
uppercase_words = [fruit.upper() for fruit in fruits]
fruit_chars = [fruit[0] for fruit in fruits]
numbers = [1, -2, 3, -4, 5, -6, 8, -7]
positive_numbers = [x for x in numbers if x >= 0]
negative_numbers = [x for x in numbers if x < 0]
even_numbers = [x for x in numbers if x % 2 == 0]
odd_numbers = [x for x in numbers if x % 2 == 1]
grades = [85, 42, 79, 90, 56, 61, 30]
passing_grades = [grade for grade in grades if grade >= 60]
I am from India what a melodious voice u have
Love your vids
Sir please continue and complete the react course
true teacher
Thanks Bro
You are both a good teacher and a good person,
i think that because you got 6000 usd for a good cause!
tutoiral on ALL of oop please
W video as always
pls make a video about explaining grid in css🙏🙏
I wonder if bro making these videos, recently . cause after making React tutorials he wants to take some time off. if it is we are all happy that you back. and we hope to learn Next.js from you.
Sit back relax and enjoy
Bro Code teaching me more in 10 minutes than my IT teacher teaching me the same material in 2 weeks😭
can u pls mmake a video about numpy arrays
loved
why is he redoing these python videos? he already had made a video on list comprehensions
150 missed calls from coding schools
When I try to run the script at 4:54, I keep getting this AttributeError and exit code 1. What happened?
you may confuse fruit (singular) with fruits (plural) if you get error , also you need to use () after fruit.upper()
upper = [ fruit.upper() for fruit in fruits]
third!
nice