[Tutor] need futher explaining
kent37 at tds.net
Mon Aug 6 13:52:21 CEST 2007
Dale Pearl wrote:
> I'm reading Beginning Python - From Novice to Professional by Magnus Lie
> Hetland (an Apress book) and there is a code example that I need further
> explaining on to fully grasp.
> There is a section with samle code of:
> names = ['anne', 'beth', 'george', 'damon']
> ages = [12, 45, 32, 102]
> for i in range(len(names)):
> print names[i], 'is', ages[i], 'years old'
bhaaluu answered your question, I just want to comment that IMO this is
not idiomatic Python. A better way to write it would be to combine the
two lists using zip():
for name, age in zip(names, ages):
print name, 'is', age, 'years old'
More information about the Tutor