Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35848

Re: Question about nested loop

From Gisle Vanem <gvanem@broadpark.no>
References <db8edd31-78f2-4e8c-a6bd-37e1e83ff2ee@googlegroups.com>
Subject Re: Question about nested loop
Date 2012-12-31 12:25 +0100
Newsgroups comp.lang.python
Message-ID <mailman.1497.1356956797.29569.python-list@python.org> (permalink)

Show all headers | View raw


"Isaac Won" <winefrog@gmail.com> wrote:

> while c < 10:
>        c = c + 1
> 
>        for  columns in ( raw.strip().split() for raw in f ):
> 
> 
>                b.append(columns[c])
> 
>        y = np.array(b, float)
>        print c, y
> 
> 
> I thought that  can get the arrays of the columns[5] to [10],
> but I only could get repetition of same arrays of columns[5].

I don't pretend to know list comprehension very well, but 
'c' isn't incremented in the inner loop ( .. for raw in f). 
Hence you only append to columns[5].

Maybe you could use another 'd' indexer inside the inner-loop?
But there must a more elegant way to solve your issue. (I'm a
PyCommer myself).

--gv

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 02:02 -0800
  Re: Question about nested loop Gisle Vanem <gvanem@broadpark.no> - 2012-12-31 12:25 +0100
    Re: Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 14:02 -0800
    Re: Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 14:02 -0800
  Re: Question about nested loop Hans Mulder <hansmu@xs4all.nl> - 2012-12-31 13:59 +0100
    Re: Question about nested loop Isaac Won <winefrog@gmail.com> - 2012-12-31 14:11 -0800

csiph-web