[Tutor] Creating new files w/o overwriting existing ones

Alan Gauld alan.gauld at btinternet.com
Mon Apr 9 17:19:47 CEST 2007

"Dick Moores" <rdm at rcblue.com> wrote 

>     lstNums = []
>     for x in lstSvg:
>         num = int(x.split('.')[0])
>         lstNums.append(num)

This is exactly what a list comp does so you could rewrite it as:

lstNums = [int(x.split('.')[0]) for x in lstSvg]

One of the cases where I actually think a list comprehension 
is more readable than the expanded code.

>     nextSVGnum = max(lstNums) + 1
>     return nextSVGnum


Alan Gauld
Author of the Learn to Program web site

More information about the Tutor mailing list