Python - If Else in a List Comprehension TUTORIAL

Поделиться
HTML-код
  • Опубликовано: 5 янв 2025

Комментарии •

  • @KelseyMeehan-zy3kx
    @KelseyMeehan-zy3kx 14 дней назад

    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!

  • @etc20292
    @etc20292 Месяц назад

    actually a goated tutorial, I have been wanting to understand list comp. for long but you really helped me, thank you!

  • @mackensonreginaldmichel399
    @mackensonreginaldmichel399 Год назад +3

    The only best tutorials on LC

  • @trunghaiha7379
    @trunghaiha7379 Год назад +2

    Thank you so much for the video, I've been looking a lot for the explanation like this. Clean & Clear.

  • @pankajmehta9204
    @pankajmehta9204 Год назад +2

    One of the best tutorial for List comprehension. Thanks for making such videos

  • @ujenetics
    @ujenetics 2 года назад +2

    I love the font size, perfect! and very clear explanations. Thank you.

  • @filled2150
    @filled2150 4 года назад +13

    Hey! you do very nice work
    You are a very good instructor

  • @MrNess2911
    @MrNess2911 9 месяцев назад +2

    Absolutely amazing tutorial! The comparison at the end allowed me to see clearly the difference. It was educational, Thank You!

  • @JayrMagave
    @JayrMagave Год назад

    Finally a good and instructive on this topic.

  • @thingsiplay
    @thingsiplay 4 года назад +5

    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.

  • @saumytiwari7
    @saumytiwari7 3 года назад +2

    thankyou so much sir :) ...it will help me in solving hackerrank problems..

    • @BrendanMetcalfe
      @BrendanMetcalfe  3 года назад +1

      nice! i will make a hackerrank series in the future

  • @killer2point057
    @killer2point057 Год назад

    I got it finally! Thank you!

  • @jalalbounaim
    @jalalbounaim 3 года назад +3

    THX , very clear🔥

  • @NeumsFor9
    @NeumsFor9 Год назад +1

    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 ..

  • @mohammadjunaidmansoori9879
    @mohammadjunaidmansoori9879 Год назад +1

    Your content is amazing. Thanks for making these videos.

  • @whynotdo93
    @whynotdo93 3 года назад +1

    This is so helpful. THANKS A LOT SIR !!!

  • @JoePescisAngryCousin
    @JoePescisAngryCousin Год назад

    Great series. Thank you!

  • @mloera81
    @mloera81 Год назад +1

    Thanks you for this video and series.

  • @abhaygargi4231
    @abhaygargi4231 5 месяцев назад +1

    Thank you sir it helped a lot.

  • @danielmorin6140
    @danielmorin6140 2 года назад

    very clear explanation, nearly made it too simple ;-)

  • @IntricateMoon
    @IntricateMoon Год назад

    THANK YOU FOR THISSSSS!!! 🤗

  • @medmankatowice
    @medmankatowice Год назад +1

    I cannot find your course on Udemy

  • @daria-pt8vt
    @daria-pt8vt Год назад

    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)

  • @vandrujemesk8651
    @vandrujemesk8651 2 года назад

    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.

  • @rishabhkaul5556
    @rishabhkaul5556 2 года назад

    @8:40
    Didnt understand the list1 bit. Why didnt you simply use 'a' instead of 'list1' ?

  • @TheRealRocketSurgeon
    @TheRealRocketSurgeon 2 года назад

    Great explanation and examples!

  • @santoshkumargouda7795
    @santoshkumargouda7795 2 года назад

    How to add the return ternery condition in list comprehension?

  • @mohammednihal6383
    @mohammednihal6383 2 года назад

    what if we wanna do a elif statement is it possible using list comprehension?

  • @arunny9430
    @arunny9430 2 года назад

    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

    • @arunny9430
      @arunny9430 2 года назад

      @@XxchristianxX14 Thank you.

  • @mehdismaeili3743
    @mehdismaeili3743 2 года назад

    Excellent

  • @liuyuenfu3728
    @liuyuenfu3728 2 года назад

    sweet..this is nice.. thanks alot

  • @Roman-rs6um
    @Roman-rs6um 2 года назад

    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?

  • @shivakannojia8963
    @shivakannojia8963 5 месяцев назад +1

    You are the best

  • @santoshkumargouda7795
    @santoshkumargouda7795 2 года назад

    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

  • @filled2150
    @filled2150 4 года назад +1

    Hey brendan Please don't stop making videos

  • @sumithkarun7352
    @sumithkarun7352 Год назад +1

    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

  • @medmankatowice
    @medmankatowice Год назад +1

    Very Nice.

  • @HassanYoussoufFossi
    @HassanYoussoufFossi 7 месяцев назад +1

    Thks a lot.

  • @allanimeworld2898
    @allanimeworld2898 3 года назад +2

    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

  • @damnryder
    @damnryder 2 года назад +1

    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?

    • @BrendanMetcalfe
      @BrendanMetcalfe  2 года назад +1

      Thanks! Can ask questions here for whole community to help

    • @damnryder
      @damnryder 2 года назад

      @@BrendanMetcalfe thanku sir for the reply...i got my answer...i have to use extend method in my list 😅😅..sorry for any inconvenience

  • @kingmoon989
    @kingmoon989 3 года назад +1

    انت بطل

  • @allanimeworld2898
    @allanimeworld2898 3 года назад +1

    Sir you teach lambda and very stuff why don't you please save them to playlist too

    • @allanimeworld2898
      @allanimeworld2898 3 года назад

      Sir can you please tell that can't we use both if and else with multiple for loops in comprehensions