home.social

#dailypythontip β€” Public Fediverse posts

Live and recent posts from across the Fediverse tagged #dailypythontip, aggregated by home.social.

  1. Python Tip #135 (of 365):

    Embrace the infinite

    Remember that infinite iterables are possible in Python.

    itertools.count() is like an infinite range().

    itertools.repeat() and itertools.cycle() are like infinite self-concatenation.

    🧡 (1/3)

    #Python #DailyPythonTip

  2. Python Tip #134 (of 365):

    Use looping helpers

    Python's "for" loops are simple: they loop over an iterable one item at a time.

    That's all they can do.

    Because our "for" loops are so simple and iterable-centric, looping helpers are a VERY big deal in Python.

    We use enumerate to count upward while looping, reversed to loop in the reverse direction, and zip to loop over multiple iterables at the same time.

    🧡 (1/2)

    #Python #DailyPythonTip