List Manipulation
Bruno Desthuilliers
onurb at xiludom.gro
Tue Jul 4 11:54:40 EDT 2006
Roman wrote:
(please dont top-post - corrected)
>
> Iain King wrote:
>
>>Roman wrote:
>>
>>>I would appreciate it if somebody could tell me where I went wrong in
>>>the following snipet:
>>>
(snip)
>>What are you trying to do here? p[:0] returns a new list, of all the
>>elements in p up to element 0 (which is of course the empty list),
>>which is then appended to, but is not stored anywhere. If you want to
>>insert str(col) then use p.insert
>>
>>
>>Iain
>
>
> Thanks for your help
>
> My intention is to create matrix based on parsed csv file. So, I
> would like to have a list of columns (which are also lists).
csv = [
['L0C0', 'L0C1', 'L0C2'],
['L1C0', 'L1C1', 'L1C2'],
['L2C0', 'L2C1', 'L2C2'],
]
matrix = [[[] for l in range(len(csv))] for c in range(len(csv[0]))]
for numline, line in enumerate(csv):
for numcol, col in enumerate(line):
matrix[numcol][numline] = col
assert matrix == [
['L0C0', 'L1C0', 'L2C0'],
['L0C1', 'L1C1', 'L2C1'],
['L0C2', 'L1C2', 'L2C2']
]
NB : There are probably more elegant solutions.
> I have made the following changes and it still doesn't work.
"doesn't work" is the worst possible description of a problem...
(snip)
--
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