On Sun, Nov 2, 2008 at 12:41 PM, spir <[EMAIL PROTECTED]> wrote:
> Sander Sweers a écrit :
>>> Note that this creates a new list, replacing the one that was in
>>> somelist. If you need to actually modify somelist in place (rare) then
>>> use somelist[:] = [ x+1 for x in somelist ]
>>>
>>> which c
Sander Sweers a écrit :
On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote:
Use a list comprehension:
somelist = [ x+1 for x in somelist ]
Got it.
Note that this creates a new list, replacing the one that was in
somelist. If you need to actually modify somelist in place (ra
On Sun, Nov 2, 2008 at 9:13 AM, Sander Sweers <[EMAIL PROTECTED]> wrote:
> On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote:
>> Note that this creates a new list, replacing the one that was in
>> somelist. If you need to actually modify somelist in place (rare) then
>> use some
On Sun, Nov 2, 2008 at 13:32, Kent Johnson <[EMAIL PROTECTED]> wrote:
> Use a list comprehension:
> somelist = [ x+1 for x in somelist ]
Got it.
> Note that this creates a new list, replacing the one that was in
> somelist. If you need to actually modify somelist in place (rare) then
> use someli
On Sat, Nov 1, 2008 at 5:40 PM, Sander Sweers <[EMAIL PROTECTED]> wrote:
> Hi,
>
> What is the better way to process data in a list? Make the changes in
> place, for example
>
> somelist = [1,2,3,4]
>
> for x in range(len(somelist)):
>somelist[x] = somelist[x] + 1
>
> Or would making a new list
On Sun, Nov 2, 2008 at 01:23, bob gailer <[EMAIL PROTECTED]> wrote:
>> What is the better way to process data in a list?
>
> Depends on what you mean by "better". Could mean faster, smaller, more
> readable, or ?? Get clear on your goals.
Inexperienced beginner programmer asking more experienced p
Sander Sweers wrote:
Hi,
What is the better way to process data in a list?
Depends on what you mean by "better". Could mean faster, smaller, more
readable, or ?? Get clear on your goals.
Make the changes in place, for example
somelist = [1,2,3,4]
for x in range(len(somelist)):
somel
Sander Sweers a écrit :
Hi,
What is the better way to process data in a list? Make the changes in
place, for example
somelist = [1,2,3,4]
for x in range(len(somelist)):
somelist[x] = somelist[x] + 1
Or would making a new list like
somelist = [1,2,3,4]
newlist = []
for x in somelist:
Hi,
What is the better way to process data in a list? Make the changes in
place, for example
somelist = [1,2,3,4]
for x in range(len(somelist)):
somelist[x] = somelist[x] + 1
Or would making a new list like
somelist = [1,2,3,4]
newlist = []
for x in somelist:
newlist.append(x + 1)
Or