How To Use List Comprehension In Python

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

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

  • @PhrontDoor
    @PhrontDoor 6 месяцев назад +3

    Loved the presentation ... very clear.
    Also could use :
    itemArr = [ f'item{n}' for n in range(3) ] to avoid the str cast

    • @igorthelight
      @igorthelight 2 месяца назад

      Python will still cast n to a string. Just implicitly.
      Correct me if I'm worong

  • @ZAR_KoWaLsKy_
    @ZAR_KoWaLsKy_ 8 месяцев назад +4

    Nice explanation! Trully useful for adding some extra spice to my projects. Keep up the good work buddy!

  • @droid812
    @droid812 4 месяца назад +1

    Very clever on zooming the code, that was a great detail
    Question: Is it recomended to use this comprehension? i mean it kinda affects readability but, what are good uses for it?

    • @TaylorsSoftware
      @TaylorsSoftware  4 месяца назад

      Great question! You should use list comprehensions when you want to quickly loop through or generate a list with minimal conditional statements. You should avoid using it when you have multiple conditions. It will make troubleshooting and readability more difficult with too many conditions.

  • @fusebox9725
    @fusebox9725 4 месяца назад +1

    perhaps we can also use append function as i.append("new") for i in itemList)

  • @igorthelight
    @igorthelight 2 месяца назад

    Also, list comprehensions are faster!

  • @jurgenblick5491
    @jurgenblick5491 7 месяцев назад

    which version of py