Intermediate Python Puzzle #1: List Comprehensions - Powerful Syntax for Building Lists in Python

Поділитися
Вставка
  • Опубліковано 31 січ 2025

КОМЕНТАРІ • 7

  • @mlc4433
    @mlc4433 2 роки тому

    Excellent. You help me understand quickly!!!

  • @tonyregalado7281
    @tonyregalado7281 3 роки тому +1

    I must say, you're great at explaining these hard to grasp concepts. Great stuff!

  • @ericschneider572
    @ericschneider572 4 роки тому

    This is a bit cleaner (or at least more interesting) than Ruby's `(1..4).map {|x| x*2 }.filter {|x| x > 2}` I suppose.
    (Weird to me that range(1, 5) in Python does not include 5, as (1..5) does in Ruby.)

    • @KrisJordan
      @KrisJordan  4 роки тому

      The common use case in range is iterating through something zero indexed, so: range(len(list)) goes from 0 to len-1

    • @KrisJordan
      @KrisJordan  4 роки тому

      Python also has map/filter with lambdas, but list comprehension syntax is cleaner in the usual cases. Two sides of a similar coin (though Python's map/filter are lazily evaluated, which is neat, I don't remember if Ruby's is but I think it's eager?)

    • @ericschneider572
      @ericschneider572 4 роки тому +1

      @@KrisJordan in Ruby you have to be specific if you want lazy evaluation. Usually it's not something thought about though.

  • @BigFatBorger
    @BigFatBorger 4 роки тому +2

    Mr. Jordan, gotta say thatI love the vids! Feet reveal at 2k?