I want to say that sometimes for loops with multiple lines can help write cleaner code if it gets too long and complicated for one line. So list comprehensions are best used for simple tasks in my opinion. And you can write for loops with less lines too, its a bit unfair comparison. In example you do not need to assign the variable i when appending, you can just get the value inside "append" method. And you can compare both if statements in one line with "and". So we are just comparing 3 lines of code against 1 in this case.
The right IFs are like a SQL WHERE. The left IFs are the CASE STATEMENTS or the transformations. Of course, we are not dealing with set based data thinking here, but it helps those SQL first folks ..
Thanks for your videos. They are clearly and comprehensibly explained. You say slowly that I can feel it. I still want to ask. You do not have a translation for some videos. I watch your videos from Slovakia and it helps me when I can get a translation for a better understanding. Good luck.
To make this fantastic list comprehension series more complete, can you please explain why a = [1,2,3,3] y=[] y = [ x for x in a if x not in y] print(y) does not print [1,2,3] but prints [1,2,3,3] also let us know what we should keep in mind while using list comprehension to avoid such errors in code
I have a question: i want to make a 'sign' function for a list. It should take a list with ints or floats and return a list of 'sign(elements)': [23, -2, 42, -29, 0] --> [1, -1, 1, -1, 0]. I want it to be one line. Is there any way I could do that?
import statitics def print_max_average(nums): x = [] for i in nums: if len(i) == 0: continue x.append(statistics.mean(i)) return max(x) if x else None # nums = [[1, 2, 3], [4, 5, 6]] nums = [[], []] print(print_max_average(nums)) Questions : How can i write in list comprehension? Please help
Please sir if you are reading this please make a video on short hand if else please tell how to use elif in it and multiple if and elif in it and nested too please🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏💓💓💓or sir if you are busy and can't make please reply
Sir you are amazing thankyou for the video...it helped me so much...I have one question related to list comprehension...is it possible to contact you sir?through email or anything?
Bro you are the bomb. Could NOT find an example or answer to this and you answered my question in the first 1:23 of your vid. Thank you!
actually a goated tutorial, I have been wanting to understand list comp. for long but you really helped me, thank you!
The only best tutorials on LC
Thanks!
Thank you so much for the video, I've been looking a lot for the explanation like this. Clean & Clear.
One of the best tutorial for List comprehension. Thanks for making such videos
Thanks!
I love the font size, perfect! and very clear explanations. Thank you.
Hey! you do very nice work
You are a very good instructor
thanks!
Absolutely amazing tutorial! The comparison at the end allowed me to see clearly the difference. It was educational, Thank You!
Thanks!
Finally a good and instructive on this topic.
I want to say that sometimes for loops with multiple lines can help write cleaner code if it gets too long and complicated for one line. So list comprehensions are best used for simple tasks in my opinion. And you can write for loops with less lines too, its a bit unfair comparison. In example you do not need to assign the variable i when appending, you can just get the value inside "append" method. And you can compare both if statements in one line with "and". So we are just comparing 3 lines of code against 1 in this case.
thanks for taking the time to comment!
thankyou so much sir :) ...it will help me in solving hackerrank problems..
nice! i will make a hackerrank series in the future
I got it finally! Thank you!
THX , very clear🔥
Thanks
The right IFs are like a SQL WHERE.
The left IFs are the CASE STATEMENTS or the transformations.
Of course, we are not dealing with set based data thinking here, but it helps those SQL first folks ..
Your content is amazing. Thanks for making these videos.
Thanks!
This is so helpful. THANKS A LOT SIR !!!
youre welcome!
Great series. Thank you!
Thanks you for this video and series.
Thanks!
Thank you sir it helped a lot.
Most welcome!
very clear explanation, nearly made it too simple ;-)
THANK YOU FOR THISSSSS!!! 🤗
I cannot find your course on Udemy
nums=[1,2,3]
result1=[]
for i in nums:
if i >1:
if i==3:
result1.append(i*5)
else:
result1.append(i)
print(result1)
Thanks for your videos. They are clearly and comprehensibly explained. You say slowly that I can feel it. I still want to ask. You do not have a translation for some videos. I watch your videos from Slovakia and it helps me when I can get a translation for a better understanding. Good luck.
@8:40
Didnt understand the list1 bit. Why didnt you simply use 'a' instead of 'list1' ?
Great explanation and examples!
Thank you 🙏
How to add the return ternery condition in list comprehension?
what if we wanna do a elif statement is it possible using list comprehension?
To make this fantastic list comprehension series more complete, can you please explain why
a = [1,2,3,3]
y=[]
y = [ x for x in a if x not in y]
print(y)
does not print [1,2,3] but prints [1,2,3,3]
also let us know what we should keep in mind while using list comprehension to avoid such errors in code
@@XxchristianxX14 Thank you.
Excellent
sweet..this is nice.. thanks alot
I have a question: i want to make a 'sign' function for a list. It should take a list with ints or floats and return a list of 'sign(elements)': [23, -2, 42, -29, 0] --> [1, -1, 1, -1, 0]. I want it to be one line. Is there any way I could do that?
You are the best
Thanks!
import statitics
def print_max_average(nums):
x = []
for i in nums:
if len(i) == 0:
continue
x.append(statistics.mean(i))
return max(x) if x else None
# nums = [[1, 2, 3], [4, 5, 6]]
nums = [[], []]
print(print_max_average(nums))
Questions : How can i write in list comprehension? Please help
Hey brendan Please don't stop making videos
thanks!
num = 11
l = [i for i in range(2, num+1) if all(i % j != 0 for j in range(2, i))]
print(l) could you please explain this code
Very Nice.
Thanks!
Thks a lot.
Np!
Please sir if you are reading this please make a video on short hand if else please tell how to use elif in it and multiple if and elif in it and nested too please🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏💓💓💓or sir if you are busy and can't make please reply
Sir you are amazing thankyou for the video...it helped me so much...I have one question related to list comprehension...is it possible to contact you sir?through email or anything?
Thanks! Can ask questions here for whole community to help
@@BrendanMetcalfe thanku sir for the reply...i got my answer...i have to use extend method in my list 😅😅..sorry for any inconvenience
انت بطل
Sir you teach lambda and very stuff why don't you please save them to playlist too
Sir can you please tell that can't we use both if and else with multiple for loops in comprehensions