Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    for animal, color in zip(['dog', 'cat', 'bird'], ['brown', 'black', 'red']):
        print 'See the %s %s?' % (color, animal)


I never knew about this zip command. I guess it brings the same utility offered by the TCL foreach loops to python.

Still, I wish more languages directly imitated the TCL foreach loop. I've found that when I code, I wish I could just do some simple task 3-4 times. I am always tempted to create a little function, and to call that function repeatedly. But that seems like overkill. With TCL, I just write a simple loop statement instead of the function. I've found that my code is more compact, and the number of functions that I declare is reduced.


Ruby too:

  ['dog', 'cat', 'bird'].zip(['brown', 'black', 'red']).each {|animal, color| puts "See the #{color} #{animal}?"}




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: