Sion Arrowsmith a écrit :
Bruno Desthuilliers wrote:
mylist = line.strip().split()
will already do the RightThing(tm).
So will
mylist = line.split()
Yeps, it's at least the second time someone reminds me that the call to
str.strip is just useless here... Pity my poor old neuron :(
--
h
On Tue, 15 Sep 2009 02:55:13 +0100, Chris Rebert wrote:
On Mon, Sep 14, 2009 at 6:49 PM, Helvin wrote:
Hi,
Sorry I did not want to bother the group, but I really do not
understand this seeming trivial problem.
I am reading from a textfile, where each line has 2 values, with
spaces before and
Bruno Desthuilliers wrote:
> >> mylist = line.strip().split()
>
>will already do the RightThing(tm).
So will
mylist = line.split()
--
\S
under construction
--
http://mail.python.org/mailman/listinfo/python-list
Dennis Lee Bieber a écrit :
(snip)
All of which can be condensed into a simple
for ln in f:
wrds = ln.strip()
# do something with the words -- no whitespace to be seen
I assume you meant:
wrds = ln.strip().split()
?-)
--
http://
Dave Angel a écrit :
(snip)
As Chris says, you're modifying the list while you're iterating through
it, and that's undefined behavior. Why not do the following?
mylist = line.strip().split(' ')
mylist = [item for item in mylist if item]
Mmmm... because the second line is plain useless when
Helvin a écrit :
Hi,
Sorry I did not want to bother the group, but I really do not
understand this seeming trivial problem.
I am reading from a textfile, where each line has 2 values, with
spaces before and between the values.
I would like to read in these values, but of course, I don't want the
good solution ,thanks~!
2009/9/15 Steven D'Aprano
> On Mon, 14 Sep 2009 18:55:13 -0700, Chris Rebert wrote:
>
> > On Mon, Sep 14, 2009 at 6:49 PM, Helvin wrote:
> ...
> > > I have looked at documentation, and how strings and lists work, but I
> > > cannot understand the behaviour of the followi
On Mon, 14 Sep 2009 18:55:13 -0700, Chris Rebert wrote:
> On Mon, Sep 14, 2009 at 6:49 PM, Helvin wrote:
...
> > I have looked at documentation, and how strings and lists work, but I
> > cannot understand the behaviour of the following:
...
> > for item in list:
> >
En Mon, 14 Sep 2009 23:33:05 -0300, tec escribió:
or use filter
list=filter(lambda x: len(x)>0, list)
For strings, len(x)>0 <=> len(x) <=> x, so the above statement is
equivalent to:
list=filter(lambda x: x, list)
which according to the documentation is the same as:
list=filter(None, li
Helvin wrote:
Hi,
Sorry I did not want to bother the group, but I really do not
understand this seeming trivial problem.
I am reading from a textfile, where each line has 2 values, with
spaces before and between the values.
I would like to read in these values, but of course, I don't want the
wh
Thanks Chris! Thanks for the quick reply. Indeed this is the case! I have
now written out a new list, instead of modifying the list I am iterating
over.
Logged at my blog:
http://learnwithhelvin.blogspot.com/2009/09/python-loop-and-modify-list.html
Regards,
Helvin =)
On Tue, Sep 15, 2009 at 1:55
Helvin 写道:
Hi,
Sorry I did not want to bother the group, but I really do not
understand this seeming trivial problem.
I am reading from a textfile, where each line has 2 values, with
spaces before and between the values.
I would like to read in these values, but of course, I don't want the
white
Chris Rebert 写道:
On Mon, Sep 14, 2009 at 6:49 PM, Helvin wrote:
Hi,
Sorry I did not want to bother the group, but I really do not
understand this seeming trivial problem.
I am reading from a textfile, where each line has 2 values, with
spaces before and between the values.
I would like to read
On Mon, Sep 14, 2009 at 6:49 PM, Helvin wrote:
> Hi,
>
> Sorry I did not want to bother the group, but I really do not
> understand this seeming trivial problem.
> I am reading from a textfile, where each line has 2 values, with
> spaces before and between the values.
> I would like to read in the
Hi,
Sorry I did not want to bother the group, but I really do not
understand this seeming trivial problem.
I am reading from a textfile, where each line has 2 values, with
spaces before and between the values.
I would like to read in these values, but of course, I don't want the
whitespaces betwee
15 matches
Mail list logo