On 03/09/18 18:49, C W wrote:
> Hello all,
>
> I am learning the basics of Python. How do I know when a method modifies
> the original object, when it does not. I have to exmaples:
> Example 1:
>> L = [3, 6, 1,4]
>> L.reverse()
>> L
> [4, 1, 6, 3]
> This changes the original list.
Lists are mutabl
Mark Lawrence Sent: Monday, September 3, 2018
2:21:36 PM To: python-list@python.org
Subject: Re: Why list.reverse() modifies the list, but name.replace() does not
modify the string?
On 03/09/18 18:49, C W wrote:
> Hello all,
>
> I am learning the basics of Python. How do I know when a m
On Tue, Sep 4, 2018 at 3:49 AM, C W wrote:
> Hello all,
>
> I am learning the basics of Python. How do I know when a method modifies
> the original object, when it does not. I have to exmaples:
> Example 1:
>> L = [3, 6, 1,4]
>> L.reverse()
>> L
> [4, 1, 6, 3]
> This changes the original list.
>
>
On Mon, Sep 3, 2018 at 1:50 PM C W wrote:
>
> Hello all,
>
> I am learning the basics of Python. How do I know when a method modifies
> the original object, when it does not. I have to exmaples:
> Example 1:
> > L = [3, 6, 1,4]
> > L.reverse()
> > L
> [4, 1, 6, 3]
> This changes the original list.
Hello all,
I am learning the basics of Python. How do I know when a method modifies the
original object, when it does not. I have to exmaples: Example 1:
> L = [3, 6, 1,4]
> L.reverse()
> L
[4, 1, 6, 3]
This changes the original list.
Example 2:
> name = "John Smith"
> name.replace("J", j")
> nam
f
of Mark Lawrence
Sent: Monday, September 3, 2018 2:21:36 PM
To: python-list@python.org
Subject: Re: Why list.reverse() modifies the list, but name.replace() does not
modify the string?
On 03/09/18 18:49, C W wrote:
> Hello all,
>
> I am learning the basics of Python. How do I know
On 03/09/18 18:49, C W wrote:
Hello all,
I am learning the basics of Python. How do I know when a method modifies
the original object, when it does not. I have to exmaples:
Example 1:
L = [3, 6, 1,4]
L.reverse()
L
[4, 1, 6, 3]
This changes the original list.
Lists are mutable, i.e. can be ch
On Tue, Sep 4, 2018 at 3:49 AM, C W wrote:
> Hello all,
>
> I am learning the basics of Python. How do I know when a method modifies
> the original object, when it does not. I have to exmaples:
> Example 1:
>> L = [3, 6, 1,4]
>> L.reverse()
>> L
> [4, 1, 6, 3]
> This changes the original list.
>
>
On Mon, Sep 3, 2018 at 1:50 PM C W wrote:
>
> Hello all,
>
> I am learning the basics of Python. How do I know when a method modifies
> the original object, when it does not. I have to exmaples:
> Example 1:
> > L = [3, 6, 1,4]
> > L.reverse()
> > L
> [4, 1, 6, 3]
> This changes the original list.
Hello all,
I am learning the basics of Python. How do I know when a method modifies
the original object, when it does not. I have to exmaples:
Example 1:
> L = [3, 6, 1,4]
> L.reverse()
> L
[4, 1, 6, 3]
This changes the original list.
Example 2:
> name = "John Smith"
> name.replace("J", j")
> nam
On Apr 29, 8:51 pm, Roy Smith <[EMAIL PROTECTED]> wrote:
> In article
> <[EMAIL PROTECTED]>,
>
> blaine <[EMAIL PROTECTED]> wrote:
> > Check out this cool little trick I recently learned:
> > >>> x=range(5)
> > >>> x.reverse() or x
> > [4, 3, 2, 1, 0]
>
> > Useful for returning lists that you need
En Tue, 29 Apr 2008 10:32:46 -0300, Roy Smith <[EMAIL PROTECTED]> escribió:
What you want to do is look at the reversed() function. Not only does it
return something (other than Null), but it is much faster because it
doesn't have to store the reversed list anywhere. What it returns is an
iter
In article
<[EMAIL PROTECTED]>,
blaine <[EMAIL PROTECTED]> wrote:
> Check out this cool little trick I recently learned:
> >>> x=range(5)
> >>> x.reverse() or x
> [4, 3, 2, 1, 0]
>
> Useful for returning lists that you need to sort or reverse without
> wasting that precious extra line :)
>
>
On Apr 29, 9:32 am, Roy Smith <[EMAIL PROTECTED]> wrote:
> The reasoning goes along the lines of, "reverse in place is an expensive
> operation, so we don't want to make it too easy for people to do". At
> least that's the gist of what I got out of the argument the many times it
> has come up.
Ex
On Tue, 29 Apr 2008 07:26:07 -0700, Paul McGuire wrote:
> On Apr 28, 1:12 pm, Mark Bryan Yu <[EMAIL PROTECTED]> wrote:
>> This set of codes works:
>>
>> >>> x = range(5)
>> >>> x.reverse()
>> >>> x
>>
>> [4, 3, 2, 1, 0]
>>
>>
> You can also use list slicing to get a reversed list:
>
x = rang
The reasoning goes along the lines of, "reverse in place is an expensive
operation, so we don't want to make it too easy for people to do". At
least that's the gist of what I got out of the argument the many times it
has come up.
It's not about the storage - it is about the in-place-modifi
On Apr 28, 1:12 pm, Mark Bryan Yu <[EMAIL PROTECTED]> wrote:
> This set of codes works:
>
> >>> x = range(5)
> >>> x.reverse()
> >>> x
>
> [4, 3, 2, 1, 0]
>
You can also use list slicing to get a reversed list:
>>> x = range(5)
>>> x
[0, 1, 2, 3, 4]
>>> x[::-1]
[4, 3, 2, 1, 0]
-- Paul
--
http://
Roy Smith a écrit :
(snip)
The reasoning goes along the lines of, "reverse in place is an expensive
operation, so we don't want to make it too easy for people to do". At
least that's the gist of what I got out of the argument the many times it
has come up.
IIRC, it's more along the line of
at least for anyone having read the doc.
>
> > > Please explain this behavior. range(5) returns a list from 0 to 4 and
> > > reverse just reverses the items on the list that is returned by
> > > range(5). Why is x None (null)?
>
> > Because that's what list
t;
> > But this doesn't:
> >
> >>>> x = range(5).reverse()
> >>>> print x
> > None
>
> This works just as expected - at least for anyone having read the doc.
>
> > Please explain this behavior. range(5) returns a list from
to 4 and
reverse just reverses the items on the list that is returned by
range(5). Why is x None (null)?
Because that's what list.reverse() returns. Call it a wart if you want
(FWIW, I do), but at least that's well documented.
--
http://mail.python.org/mailman/listinfo/python-list
one
>
> Please explain this behavior. range(5) returns a list from 0 to 4 and
> reverse just reverses the items on the list that is returned by
> range(5). Why is x None (null)?
have you tried typing help(list.reverse) at the interactive prompt?
--
Arnaud
--
http://mail.python.org/mailman/listinfo/python-list
Mark Bryan Yu wrote:
This set of codes works:
x = range(5)
x.reverse()
x
[4, 3, 2, 1, 0]
But this doesn't:
x = range(5).reverse()
print x
None
Please explain this behavior. range(5) returns a list from 0 to 4 and
reverse just reverses the items on the list that is
This set of codes works:
>>> x = range(5)
>>> x.reverse()
>>> x
[4, 3, 2, 1, 0]
But this doesn't:
>>> x = range(5).reverse()
>>> print x
None
Please explain this behavior. range(5) returns a list from 0 to 4 and
reverse just reverses the items on the list that is returned by
range(5). Why is x
24 matches
Mail list logo