The sets module is no longer needed, as we have the built-in sets
type. Its even getting a literal syntax soon.
As for the original problem, I agree on the homework smell.
On Jun 15, 2008, at 9:31 PM, takayuki wrote:
Dennis,
thanks for your reply. unfortunately i accidentally posted only h
Dennis,
thanks for your reply. unfortunately i accidentally posted only half
of my question! the "real" post should be up now.
my apologies.
takayuki
On Jun 16, 10:15 am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote:
> On Sun, 15 Jun 2008 17:18:54 -0700 (PDT), takayuki
> <[EMAIL PROTECTED]> d
Hi everyone,
I'm studying python via the excellent "how to think like a python
programmer" book by Allen Downey. Noob question follows...
I have a txt file (animals.txt) which contains the following text each
on a separate line: aardvark, bat, cat, dog, elephant, fish, giraffe,
horse, inchworm,
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
Hi,
I'm currently writing my own CSV parser since the built in one doesn't
support Unicode. I'm wondering if there's a way to iterate over the
characters in a unicode string and have access to both the 'current' and the
'next' characters each iteration. For example:
test = u"Hello World"
for cur
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: [email protected]
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
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..
i can't figure out how to accomplish this...
can someone point me to how/where this is demonstrated...
found plenty of google for for/loo
26 matches
Mail list logo