[EMAIL PROTECTED] (Alex Martelli) wrote in
news:[EMAIL PROTECTED]:
> Aahz <[EMAIL PROTECTED]> wrote:
>> I would agree with people who claim
>> that you should memorize most of the built-in functions (which is
>> precisely why there is a high barrier to adding more built-in
>> functions).
>
> I
Jan Vorwerk <[EMAIL PROTECTED]> wrote:
> [ lots of sensible stuff to discover "reversed" ]
> >>> print reversed.__doc__
See also:
>>> help(reversed)
--
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
"Frankly I have no feelings towards penguins one way or the other"
-- Arth
Martin Durkin a écrit , le 02.07.2007 06:38:
> This is an interesting point to me. I am just learning Python and I
> wonder how I would know that a built in function already exists?
> At what point do I stop searching for a ready made solution to a
> particular problem and start programming my o
Aahz <[EMAIL PROTECTED]> wrote:
...
> This works in all versions of Python back to 1.5.2 IIRC. reversed() is
> a moderately new built-in function;
Yep: it came with Python 2.4, first alpha just 4 years ago, final
release about 3 years and 8 months ago. "Moderately new" seems an
appropriate ta
In article <[EMAIL PROTECTED]>,
Martin Durkin <[EMAIL PROTECTED]> wrote:
>[EMAIL PROTECTED] (Alex Martelli) wrote in
>news:[EMAIL PROTECTED]:
>>
>> So, something like:
>>
>> for c in reversed(x): print c
>>
>> is mostly likely how I'd present the solution to the task.
>
>This is an interesting
Martin Durkin <[EMAIL PROTECTED]> writes:
> Is it just a matter of reading *all* the documentation before I start
> coding?
It's worth spending an hour or two reading through the library manual,
yes.
--
http://mail.python.org/mailman/listinfo/python-list
[EMAIL PROTECTED] (Alex Martelli) wrote in
news:[EMAIL PROTECTED]:
> Martin Durkin <[EMAIL PROTECTED]> wrote:
>...
>> >> def rev(x):
>> >>> mylist = []
>> >>> for char in x:
>> >>> mylist.append(char)
>> >>> mylist.reverse()
>> >>>
Alex Martelli wrote:
> since what you're doing is...:
>
s = "onomatopoeia"
s = s.join(s[::-1])
s
> 'aonomatopoeiaionomatopoeiaeonomatopoeiaoonomatopoeiaponomatopoeiaoonoma
> topoeiatonomatopoeiaaonomatopoeiamonomatopoeiaoonomatopoeianonomatopoeia
> o'
>
> ...which isn't really jus
Alex Martelli wrote:
> Martin Durkin <[EMAIL PROTECTED]> wrote:
>...
> print "\n".join("spam"[::-1])
>...
OK, maybe I'm missing the point here as I'm new to Python. The first
one seems clearer to me. What am I missing?
>>> I think all you are missing is familarity wit
Jay Loden <[EMAIL PROTECTED]> wrote:
...
> For what it's worth, with python 2.5 on my Macbook:
Hmmm, doesn't look to me as if it's worth much...:
> [EMAIL PROTECTED] jloden]$ python -m timeit 's = "onomatopoeia"; s =
s.join(s[::-1])'
since what you're doing is...:
>>> s = "onomatopoeia"
>>>
Martin Durkin <[EMAIL PROTECTED]> wrote:
...
> >> def rev(x):
> >>> mylist = []
> >>> for char in x:
> >>> mylist.append(char)
> >>> mylist.reverse()
> >>> for letter in mylist:
> >>> print letter
> >>>
> >>>
Evan Klitzke wrote:
>
>> I guess that's it. The first one reads more like a textbook example which
>> is about where I am at. Is there any speed benefit from the one liner?
>
> The one line is quite a bit faster:
>
> [EMAIL PROTECTED] ~ $ python -m timeit 's = "onomatopoeia"; s =
> s.join(s[::-
On 1 Jul 2007 11:09:40 GMT, Martin Durkin <[EMAIL PROTECTED]> wrote:
> Duncan Booth <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]:
>
> > Martin Durkin <[EMAIL PROTECTED]> wrote:
> >
> >> def rev(x):
> >>> mylist = []
> >>> for char in x:
> >>> my
Martin Durkin wrote:
> Duncan Booth <[EMAIL PROTECTED]> wrote in
> news:[EMAIL PROTECTED]:
>
>> Martin Durkin <[EMAIL PROTECTED]> wrote:
>>
>>> def rev(x):
mylist = []
for char in x:
mylist.append(char)
mylist.reverse()
Duncan Booth <[EMAIL PROTECTED]> wrote in
news:[EMAIL PROTECTED]:
> Martin Durkin <[EMAIL PROTECTED]> wrote:
>
>> def rev(x):
>>> mylist = []
>>> for char in x:
>>> mylist.append(char)
>>> mylist.reverse()
>>> for letter in myl
Martin Durkin <[EMAIL PROTECTED]> wrote:
> def rev(x):
>> mylist = []
>> for char in x:
>> mylist.append(char)
>> mylist.reverse()
>> for letter in mylist:
>> print letter
>>
>> However, compare the incredible d
ptn <[EMAIL PROTECTED]> wrote in news:1182997438.541012.54100
@o61g2000hsh.googlegroups.com:
>
def rev(x):
> mylist = []
> for char in x:
> mylist.append(char)
> mylist.reverse()
> for letter in mylist:
> print
> mylist = []
>
> That's bad. If you need to use a list in the rev function, you
> should bind a new list to a local variable inside rev.
>
He's right. If you want to use a list to temporarily store the
reversed version of your string, it should exist only in the local
namespace of your funct
>
> or one letter per line:
>
> >>> print "\n".join("spam"[::-1])
>
> m
> a
> p
> s
>
One liners rock ;)
--
http://mail.python.org/mailman/listinfo/python-list
On 2007-06-27, Scott <[EMAIL PROTECTED]> wrote:
> Yeah I know strings == immutable, but question 1 in section
> 7.14 of "How to think like a computer Scientist" has me trying
> to reverse one.
No, it just wants to to print the characters in reverse, one per
line.
> I've come up with two things, o
"Scott" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| Yeah I know strings == immutable, but question 1 in section 7.14 of "How
to
| think like a computer Scientist" has me trying to reverse one.
>>> 'this is a test'[::-1]
'tset a si siht'
--
http://mail.python.org/mailman/l
> Původní zpráva
> Od: Will Maier <[EMAIL PROTECTED]>
> Předmět: Re: Reversing a string
> Datum: 27.6.2007 19:08:40
>
> On Wed, Jun 27, 2007 at 12:53:36PM -0400, Scott wrote:
> > So how on earth wou
Scott wrote:
> Yeah I know strings == immutable, but question 1 in section 7.14 of "How
> to think like a computer Scientist" has me trying to reverse one.
>
> I've come up with two things, one works almost like it should except that
> every traversal thru the string I've gotten it to repeat the
Scott wrote:
> So how on earth would be the best way to: Write a function that takes a
> string as an argument and outputs the letters backward, one per line.
Homework?
Anyway, what about:
for c in string[::-1]:
print c
Stefan
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, Jun 27, 2007 at 12:53:36PM -0400, Scott wrote:
> So how on earth would be the best way to: Write a function that
> takes a string as an argument and outputs the letters backward,
> one per line.
>>> def rev(forward):
... backward = list(forward)
... backward.reverse()
Yeah I know strings == immutable, but question 1 in section 7.14 of "How to
think like a computer Scientist" has me trying to reverse one.
I've come up with two things, one works almost like it should except that
every traversal thru the string I've gotten it to repeat the "list" again.
This is
26 matches
Mail list logo