List Manipulation
Bruno Desthuilliers
onurb at xiludom.gro
Wed Jul 5 05:29:42 EDT 2006
Mike Kent wrote:
(snip)
> p[j] does not give you a reference to an element inside p.
Yes it does:
>>> a = ['a']
>>> b = ['b']
>>> c = ['c']
>>> p = [a, b, c]
>>> p[0] is a
True
>>> p[1] is b
True
>>> p[2] is c
True
>>> p[0].append('z')
>>> a
['a', 'z']
>>>
> It gives
> you a new sublist containing one element from p.
Plain wrong.
> You then append a
> column to that sublist. Then, since you do nothing more with that
> sublist, YOU THROW IT AWAY.
Plain wrong.
> Try doing:
>
> p[j] = p[j].append(col)
Plain wrong again. list.append() returns None, so the following code:
- retrieve a reference to p[j] (which happens to be a list)
- append something to that list
- then rebind p[j] to None...
> However, this will still result in inefficient code.
Indeed. One could even say "broken" and "braindead".
> Since every line
> you read in via the csv reader is already a list, try this (untested)
Given your obvious lack of even the most basic knowledge concerning
Python, it would be better for you *and everyone reading this newsgroup*
that you take time to actually test before posting.
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"
More information about the Python-list
mailing list