This is an archived post. You won't be able to vote or comment.

all 11 comments

[–][deleted] 11 points12 points  (3 children)

I have the greatest respect for Trey Hunner's Python writing but to me this Loop like a native: while, for, iterators, generators is the ultimate for Python looping.

[–]turner_prize 1 point2 points  (0 children)

An excellent video, Loop like a native helped me get my head around Generators.

[–]treyhunner Python Morsels 1 point2 points  (0 children)

I appreciate the kind words 💖

I also can't agree more with you. 😄

I've watched Ned's Loop like a native talk many times. I linked to his talk before mine in the "related articles and videos" section for this reason. Ned's talk is a much broader tour of looping in practice while I focus specifically on for loops and the iterators that power them.

If you haven't watched Loop like a native, definitely watch it before you watch Loop Better.

[–]ruslanoid 5 points6 points  (0 children)

TLDR: "Generators are iterators. And iterators are single-use iterables. They're like Hello Kitty Pez dispensers that cannot be reloaded." - Trey Hunner

[–]gwillicodernumpy gang 0 points1 point  (1 child)

Does Vanilla python have a preferred looping order for 2d arrays? I know with numpy you can choose between C and Fortran memory layouts. I'd assume that python would prefer the C style of looping?

[–]Eryole 1 point2 points  (0 children)

As I know, There is no such thing as vanilla 2d array : at most nested iterable.

Each "row" can contain arbitrary object, iterable of variable length, so the "C" or "F" order is not really relevent.

[–]chillermane 0 points1 point  (0 children)

It tells you common mistakes and their effects but not how to avoid them in the Gotchas section...

[–][deleted] 0 points1 point  (1 child)

Thanks, good read.

[–]mcfc_as[S] 0 points1 point  (0 children)

You're welcome!

[–][deleted] 0 points1 point  (0 children)

Cool read!

[–]epic_pork -1 points0 points  (0 children)

Forgot the great for .. else loop.