[Tutor] Creating new files w/o overwriting existing ones
Kent Johnson
kent37 at tds.net
Mon Apr 9 20:27:40 CEST 2007
Alan Gauld wrote:
> "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.
And from there it is just one more step to skip the list completely:
nextSVGnum = max(int(x.split('.')[0]) for x in lstSvg) + 1
Kent
More information about the Tutor
mailing list