Implicit lists
Alex Martelli
aleax at aleax.it
Thu Jan 30 11:29:25 EST 2003
holger krekel wrote:
...
> hmmm. Maybe with a general-purpose
>
> def elems(*args):
> l = []
> for arg in args:
> try: l.extend(arg)
> except TypeError: l.append(arg)
> return l
Alas, doesn't meet specs...:
[alex at lancelot mydata]$ python2.2
Python 2.2.2 (#1, Oct 24 2002, 11:43:01)
[GCC 2.96 20000731 (Mandrake Linux 8.2 2.96-0.76mdk)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> a=[]
>>> a.extend('ciao')
>>> a
['c', 'i', 'a', 'o']
>>>
basically, l.extend now accepts all iterables. Handy in
most cases, but hardly ever what one wants for strings.
Alex
More information about the Python-list
mailing list