[Tutor] something relevant to array

Alan Gauld alan.gauld at btinternet.com
Fri Dec 23 13:01:19 CET 2011


On 23/12/11 11:02, lina wrote:

>      for i in range(len(result)):
>          for j in range(len(result[i])):
>              print(result[i][j])

You don't need all the indexing.
Use Pythons for loop to get the items:

for group in result:
    for item in group:
        print item,     # comma prevents auto newline

It's easier to read and less processing for the computer.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list