Python tutorial - List comprehensions with Multiple 'Ifs' Explained (Conditionals and Filtering)

preview_player
Показать описание
Python tutorial on list comprehensions with multiple if statements explained. Learn how to use multiple if statements within a list comprehension, double ifs, and how the conditional logic works. We also program examples with multiple for loops and multiple if statements.

❗❗This video is part of a SERIES. Check out the other videos below ❗❗

💻 Python List Comprehensions Course Playlist:

💻 Python Interview Questions Playlist:

📖 The complete Udemy course on Python Built-in Functions:

⚙️ Recommended Computer Gear:

✈️ Recommended Digital Nomad Gear:
Рекомендации по теме
Комментарии
Автор

I was literally searching for this. Awesome work in a simple way you have explained I am new to Python was stuck with this. Thank you

AbhinavKumar-dref
Автор

That is the real Best Ultimate Guide to Python LC

mackymichel
Автор

The last three list comprehension videos of yours I just watched makes it really clear. For some reason, in the past, list comprehensions seemed so random, but not anymore!

drivers
Автор

I never thought I could find something like this. I'm amazed!😃

MrNess
Автор

Thanks very much for this video series man!!

josiahdavid
Автор

@Brendan Metcalfe You are by far the best I have watched in terms of explanation and breaking down each problem statement . Simply amazing !!

I have messaged you on linkedin as well. Please come out with a playlist on the below topics . It will be super helpful- :

1) Numpy, python libraries
2) Pandas
3) Regular Expressions
4) OOP concepts

rishabhkaul
Автор

what i'm getting so far is that "list comprehensions = squashing for loops into 1 line so they are less readable"

manfrombritain
Автор

The reason the outputs aren't the same at 7:20 is because the first one is a list, the second one is just printing the individual results inside the nested for.

TheLKStar
Автор

Hey Brendan, thank you for the video! I tried to solve a problem with it but I'm still stuck (for 4 hours straight) ... May I ask you for advice?
I have a dataframe with several columns. I now want to create a new columns that contains a string ("yes") if 1.) one of the columns (column name: condition) contains a certain string-value ("pictures") and 2.) the float-value of another colums (column name: rt for reaction time) is > 0.5. And if the first column ("condition") contains the same string-value ("pictures") but the other column has a float-value <= 0.5, I want a "no" as a value in my new colum. (I hope the situation is understandable, sorry that it sounds so complicated). What I have so far:
df["new_column"] = ["yes" if i > 0.5 else "no" for i in df.rt] --> but this only contains the condition referring to the reaction time (rt) > or <= 0.5. It does not contain the other condition. But because the other condition refers to another column, I don't know how to write the code. I'd be utterly grateful for any hint how to solve the problem!!!!

ElowenFaye
Автор

How about print((i, f), end=“, “)? This way you might get similar outputs.

danyar
Автор

I was hoping you were going to include adding unique list items so you would only have one entry per fruit with the number of summed. I don’t know if that can be done in the list comprehension or not.

KrazyMO
Автор

which terminal you using and how are you able to get auto completion in it ?

vishaljuneja
Автор

Sir can you please tell me which side was just you visiting in starting where you show us info of list comprehension

allanimeworld
Автор

great video, where can I find your code?

ricardodiaz
Автор

ahh so its basically creating new sub nested parts when adding an item to the right

JVenom_