Odd listcomp behaviour

Emile van Sebille emile at fenx.com
Fri Dec 17 18:08:44 EST 2010


Does anyone else consider this a bug?

Python 2.6.2 (r262:71600, Jun 16 2009, 11:09:39)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

---1---
 >>> skippedords = '1,2,3,4,5'
 >>> ['10%s' % ii for ii in skippedords.split(',')]
['101', '102', '103', '104', '105']

---2---
 >>> skippedords = ''
 >>> ['10%s' % ii for ii in skippedords.split(',')]
['10']

---3---
 >>> test = ''
 >>> ['%s' % ii for ii in test.split() ]
[]


I got stung because I expected ---2--- to do what ---3--- did.

Emile




More information about the Python-list mailing list