Steven D'Aprano <[EMAIL PROTECTED]> writes:
> >> >>> pairs = (test[i:i+2] for i in xrange(len(test)-1))
> >> >>> for a,b in pairs:
> >> ... print a,b
> >
> > for a, b in zip(test, test[1:]):
> > print a, b
>
> May be unfortunately slow if test is half a gigabyte of data, what with
> ess
On Oct 11, 4:40 am, Steven D'Aprano <[EMAIL PROTECTED]
cybersource.com.au> wrote:
> On Wed, 10 Oct 2007 20:25:00 +, Paul Hankin wrote:
> >> A "works-for-me":
>
> >> >>> pairs = (test[i:i+2] for i in xrange(len(test)-1))
> >> >>> for a,b in pairs:
> >> ... print a,b
>
> > for a, b in zip(
On Wed, 10 Oct 2007 20:25:00 +, Paul Hankin wrote:
>> A "works-for-me":
>>
>> >>> pairs = (test[i:i+2] for i in xrange(len(test)-1))
>> >>> for a,b in pairs:
>> ... print a,b
>
> for a, b in zip(test, test[1:]):
> print a, b
May be unfortunately slow if test is half a gigabyte of da
On 10/10/07, Carsten Haese <[EMAIL PROTECTED]> wrote:
>
> Instead of passing the file object directly to the csv parser, pass in a
> generator that reads from the file and explicitly encodes the strings
> into UTF-8, along these lines:
>
> def encode_to_utf8(f):
> for line in f:
> yield
On Wed, 2007-10-10 at 16:03 -0500, Robert Dailey wrote:
> I've tried everything to make the original CSV module work. It just
> doesn't. I've tried UTF-16 encoding
What do you mean, "tried?" Don't you know what the file is encoded in?
> (which works fine with codecs.open()) but when I pass in th
I've tried everything to make the original CSV module work. It just doesn't.
I've tried UTF-16 encoding (which works fine with codecs.open()) but when I
pass in the file object returned from codecs.open() into csv.reader(), the
call to reader.next() fails because it says something isnt' in the rang
Tim Chase wrote:
>> test = u"Hello World"
>>
>> for cur,next in test:
>> print cur,next
>>
>> Ideally, this would output:
>>
>> 'H', 'e'
>> 'e', 'l'
>> 'l', 'l'
>> 'l', 'o'
>> etc...
>>
>> Of course, the for loop above isn't valid at all. I am just giving an
>> example of what I'm trying to acc
On Oct 10, 4:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > test = u"Hello World"
>
> > for cur,next in test:
> > print cur,next
>
> > Ideally, this would output:
>
> > 'H', 'e'
> > 'e', 'l'
> > 'l', 'l'
> > 'l', 'o'
> > etc...
>
> > Of course, the for loop above isn't valid at all. I am just
Paul Hankin wrote:
> On Oct 10, 9:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
>> >>> pairs = (test[i:i+2] for i in xrange(len(test)-1))
>> >>> for a,b in pairs:
>> ... print a,b
>
> for a, b in zip(test, test[1:]):
> print a, b
Very nice!
I second this solution as better than my original
Very nice solution :)
On 10/10/07, Paul Hankin <[EMAIL PROTECTED]> wrote:
>
> On Oct 10, 9:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > > test = u"Hello World"
> >
> > > for cur,next in test:
> > > print cur,next
> >
> > > Ideally, this would output:
> >
> > > 'H', 'e'
> > > 'e', 'l'
> > >
All the ideas presented here are workable. I definitely have a lot of
solutions to choose from. Thanks everyone for your help. I wasn't sure if
there was some sort of language feature to naturally do this, so I had to
post on the mailing list to make sure.
--
http://mail.python.org/mailman/listinf
On Oct 10, 9:12 pm, Tim Chase <[EMAIL PROTECTED]> wrote:
> > test = u"Hello World"
>
> > for cur,next in test:
> > print cur,next
>
> > Ideally, this would output:
>
> > 'H', 'e'
> > 'e', 'l'
> > 'l', 'l'
> > 'l', 'o'
> > etc...
>
> > Of course, the for loop above isn't valid at all. I am just
On Wed, 2007-10-10 at 14:56 -0500, Robert Dailey wrote:
> Hi,
>
> I'm currently writing my own CSV parser since the built in one doesn't
> support Unicode.
Why do you think you need a CSV parser that supports unicode?
--
Carsten Haese
http://informixdb.sourceforge.net
--
http://mail.python.o
> test = u"Hello World"
>
> for cur,next in test:
> print cur,next
>
> Ideally, this would output:
>
> 'H', 'e'
> 'e', 'l'
> 'l', 'l'
> 'l', 'o'
> etc...
>
> Of course, the for loop above isn't valid at all. I am just giving an
> example of what I'm trying to accomplish. Anyone know how I c
Try this:
test = u"Hello World"
n = range(len(test))
for i in n:
cur = test[i]
try:
next = test[i+1]
except:
next = ""
print cur, next
just
On 10/10/07, Robert Dailey <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> I'm currently writing my own CSV parser since the built in on
for a in range(2, len(foo)): print a
or maybe you need
for a in range(1, len(foo)): print a
?
York
bruce wrote:
> hi..
>
> basic foor/loop question..
>
> i can do:
>
> for a in foo
> print a
>
> if i want to do something like
> for a, 2, foo
> print foo
>
> where go from 2, to foo
> Except that in the OP's example foo was a sequence, not an
> integer. I think.
Yes, possibly. But then, what's "from 2 to foo"?
this way it might be
for a in [2] + foo:
print a
--
http://mail.python.org/mailman/listinfo/python-list
On 2006-07-06, Daniel Haus <[EMAIL PROTECTED]> wrote:
>> i can do:
>>
>> for a in foo
>> print a
>>
>> if i want to do something like
>> for a, 2, foo
>> print foo
>>
>> where go from 2, to foo..
> just do:
>
> for a in range(2, foo+1):
> print a
Except that in the OP's example foo
'ppreaciate the answers
duh...
-bruce
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf
Of Daniel Haus
Sent: Thursday, July 06, 2006 2:02 PM
To: python-list@python.org
Subject: Re: for loop question
just do:
for a in range(2, foo+1):
print a
just do:
for a in range(2, foo+1):
print a
range(a, b) gives [a, a+1, a+2, ..., b-2, b-1]
bruce schrieb:
> hi..
>
> basic foor/loop question..
>
> i can do:
>
> for a in foo
> print a
>
> if i want to do something like
> for a, 2, foo
> print foo
>
> where go from 2, to foo..
>
>
On 7/6/06, bruce <[EMAIL PROTECTED]> wrote:
hi..basic foor/loop question..i can do: for a in foo print aif i want to do something like for a, 2, fooprint foowhere go from 2, to foo..i can't figure out how to accomplish this...
can someone point me to how/where this is demonstrated...You might
21 matches
Mail list logo