List Manipulation

Roman rgelfand2 at hotmail.com
Tue Jul 4 13:39:22 EDT 2006


Thanks for spending so much time  with me.  I had since made the
following change.

matrix = [[[] for l in range(len(list(reader)[:10]))] for c in
range(len(list(reader)[7]))]
for numline, line in enumerate(reader):
   for numcol, col in enumerate(line):
       matrix[numcol][numline] = col

print matrix

I don't get mistakes anymore.  However, still nothing gets printed
Bruno Desthuilliers wrote:
> 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