Better HN
topnewbestaskshowjobs
Log inSign up

jppbkm

1 karma · joined Jul 12, 2023 (3y ago) · 1 submissions

Submissions

comment 3y ago · link · parent

Aww, zip is great!

  for x,y in zip(['a', 'b', 'c'], ['1', '2', '3']):

     print(x + y)

  >>'a1'

  >>'b2'

  >>'c3'
Usually you just use it to group two items you're iterating through that are the same length. You CAN do items of different lengths but then when one gets used up the rest of the other get tossed IIRC. Can use it in list comprehensions as well of course.

Zip was simpler than I thought when I first saw it.