On Sun, 18 Oct 2009 23:04:36 -0700 (PDT),
alex23 wrote:
> On Oct 19, 3:53 pm, Jabba Laci wrote:
>> Would someone explain how str[::-1] work? I'm new to Python and I only
>> saw so far the str[begin:end] notation. What is the second colon?
>
> Slice notation is of the form [start:stop:step
Paul Rubin:
> If you want to peel off digits from an int one by one without string
> conversions, it's easiest to do that in reverse order:
>
> n = 961
> digits = []
> while n > 0:
> n,d = divmod(n, 10)
> digits.append(d)
>
> Look up the docs for "divmod" for an explanation of that h
alex23 wrote:
> The only mention I could find was
> http://docs.python.org/dev/3.0/library/functions.html#slice
No idea why that link was the one that came up, this is more
appropriate:
http://docs.python.org/3.1/library/functions.html#slice
--
http://mail.python.org/mailman/listinfo/python-l
On Oct 19, 3:53 pm, Jabba Laci wrote:
> Would someone explain how str[::-1] work? I'm new to Python and I only
> saw so far the str[begin:end] notation. What is the second colon?
Slice notation is of the form [start:stop:step]. start defaults to the
start of the sequence, stop to the end, and ste
On Sun, Oct 18, 2009 at 10:53 PM, Jabba Laci wrote:
> Hi,
>
> Would someone explain how str[::-1] work? I'm new to Python and I only
> saw so far the str[begin:end] notation. What is the second colon?
Specifies the step value, as in: foo[start:stop:step]
When not specified it, defaults to 1.
S
Hi,
Would someone explain how str[::-1] work? I'm new to Python and I only
saw so far the str[begin:end] notation. What is the second colon?
Thanks,
Laszlo
> Here is a simplistic version that doesn't use fancy math:
>
str(24)
> '24'
str(24)[::-1]
> '42'
int(str(24)[::-1])
> 42
--
Paul Rubin wrote:
> Yet another way is to use recursion. I'll leave that as an exercise too.
This time with big numbers:
def trampoline(bouncing, *args, **kwargs):
while bouncing:
result, bouncing, args, kwargs = bouncing(*args, **kwargs)
if result:
return result
Benjamin Middaugh wrote:
I'm trying to make an integer that is the reverse of an existing integer
such that 169 becomes 961. I guess I don't know enough yet to figure out
how to do this without a ton of awkward-looking code. I've tried for
loops without much success. I guess I need a good way o
Benjamin Middaugh writes:
> I'm trying to make an integer that is the reverse of an existing
> integer such that 169 becomes 961. I guess I don't know enough yet to
> figure out how to do this without a ton of awkward-looking code. I've
> tried for loops without much success. I guess I need a good
Benjamin Middaugh schrieb:
> I'm trying to make an integer that is the reverse of an existing integer
> such that 169 becomes 961. I guess I don't know enough yet to figure out
> how to do this without a ton of awkward-looking code. I've tried for
> loops without much success. I guess I need a g
On Sun, 18 Oct 2009 19:34:09 +0100, Benjamin Middaugh
wrote:
I'm trying to make an integer that is the reverse of an existing integer
such that 169 becomes 961. I guess I don't know enough yet to figure out
how to do this without a ton of awkward-looking code. I've tried for
loops withou
Benjamin Middaugh wrote:
I'm trying to make an integer that is the reverse of an existing integer
such that 169 becomes 961. I guess I don't know enough yet to figure out
how to do this without a ton of awkward-looking code. I've tried for
loops without much success. I guess I need a good way o
I'm trying to make an integer that is the reverse of an existing integer
such that 169 becomes 961. I guess I don't know enough yet to figure out
how to do this without a ton of awkward-looking code. I've tried for
loops without much success. I guess I need a good way of figuring out
the length
13 matches
Mail list logo