Python Love :)

M

mwt

I've only been goofing around with Python for about a month now, but
already I am in love.
I never get that feeling -- so common with Java -- that I'm swimming
upstream, struggling to force the language to do what I want.
Python makes it feel effortless and easy.
 
R

rtilley

BWill said:
and ixnay on the ubyray or else I'll tell you where to stick your
endblock delimiter :p

OK, I can't help it... which is more readable:

a_string.reverse (ruby)
a_string[::-1] (python)
 
G

gregarican

Paul said:
reversed(a_string) (python)

Which version of Python offers this function? It doesn't seem to be
available in the 2.3 version I have installed...
 
P

Paul Rubin

gregarican said:
Which version of Python offers this function? It doesn't seem to be
available in the 2.3 version I have installed...

I think it's new in 2.4.
 
P

Peter Otten

Paul said:
I think it's new in 2.4.

Needs a little help, though:
.... def __reversed__(self):
.... return self[::-1]
....'abba'

Now if only I had picked a better example :)

Peter
 
P

Paul Rubin

Peter Otten said:
<reversed object at 0x4029454c>

Darn, yes, that's the second time in the past couple weeks I've made
that exact same error in a clpy post. So what's the most concise way
of turning it back into a string? ''.join(list(reversed(a_string))) ?
Bleccch.
 
K

Kent Johnson

Paul said:
So what's the most concise way
of turning it back into a string? ''.join(list(reversed(a_string))) ?

You don't need the list(), join() can take an iterator:

''.join(reversed(a_string))

Kent
 
G

gregarican

Paul said:
Darn, yes, that's the second time in the past couple weeks I've made
that exact same error in a clpy post. So what's the most concise way
of turning it back into a string? ''.join(list(reversed(a_string))) ?
Bleccch.

Use Ruby:

print "A String".reverse

Just kidding :)~
 
P

Paddy

BWill said:
and ixnay on the ubyray or else I'll tell you where to stick your
endblock delimiter :p

Umm,
Did you mean to write the above?
What has it to do with Ruby?
 
P

Paul Rubin

gregarican said:
reversed(a_string) (python

Which version of Python offers this function? It doesn't seem to b
available in the 2.3 version I have installed..
I think it's new in 2.4
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,290
Messages
2,571,453
Members
48,129
Latest member
DianneCarn

Latest Threads

Top