On Tue, Nov 30, 2021 at 6:45 AM dn via Python-list
wrote:
>
>
>
> On 27/11/2021 21.23, Chris Angelico wrote:
> > On Sat, Nov 27, 2021 at 7:21 PM dn via Python-list
> > wrote:
> >> The expression list is evaluated once; it should yield an iterable
> >> object. An iterator is created for the result
On 27/11/2021 21.23, Chris Angelico wrote:
> On Sat, Nov 27, 2021 at 7:21 PM dn via Python-list
> wrote:
>> The expression list is evaluated once; it should yield an iterable
>> object. An iterator is created for the result of the expression_list.
>> The suite is then executed once for each item
On Sat, Nov 27, 2021 at 7:21 PM dn via Python-list
wrote:
> The expression list is evaluated once; it should yield an iterable
> object. An iterator is created for the result of the expression_list.
> The suite is then executed once for each item provided by the iterator,
> in the order returned b
On 27/11/2021 19.11, Frank Millman wrote:
> On 2021-11-26 11:24 PM, dn via Python-list wrote:
>> On 26/11/2021 22.17, Frank Millman wrote:
>>> In my program I have a for-loop like this -
>>>
>> for item in x[:-y]:
>>> ... [do stuff]
>>>
>>> 'y' may or may not be 0. If it is 0 I want to proce
On 2021-11-26 11:24 PM, dn via Python-list wrote:
On 26/11/2021 22.17, Frank Millman wrote:
In my program I have a for-loop like this -
for item in x[:-y]:
... [do stuff]
'y' may or may not be 0. If it is 0 I want to process the entire list
'x', but of course -0 equals 0, so it returns an
On 2021-11-26 11:17 AM, Frank Millman wrote:
Are there any other techniques anyone can suggest, or is the only
alternative to use if...then...else to cater for y = 0?
x[:-y or None]
Seems to work:
>>> l
['a', 'b', 'c', 'd', 'e']
>>> def f(x): return l[:-x or None]
...
>>> f(3)
['a', 'b']
>>>
Il giorno venerdì 26 novembre 2021 alle 10:23:46 UTC+1 Frank Millman ha scritto:
> Hi all
>
> In my program I have a for-loop like this -
>
> >>> for item in x[:-y]:
> ...[do stuff]
>
> 'y' may or may not be 0. If it is 0 I want to process the entire list
> 'x', but of course -0 equals
Frank Millman writes:
> Hi all
>
> In my program I have a for-loop like this -
>
for item in x[:-y]:
> ... [do stuff]
>
> 'y' may or may not be 0. If it is 0 I want to process the entire list
> 'x', but of course -0 equals 0, so it returns an empty list.
>
> In theory I can say
>
for
On 26/11/2021 22.17, Frank Millman wrote:
> In my program I have a for-loop like this -
>
for item in x[:-y]:
> ... [do stuff]
>
> 'y' may or may not be 0. If it is 0 I want to process the entire list
> 'x', but of course -0 equals 0, so it returns an empty list.
...
> But in my actual p
On 2021-11-26 11:17 AM, Frank Millman wrote:
Hi all
In my program I have a for-loop like this -
>>> for item in x[:-y]:
... [do stuff]
'y' may or may not be 0. If it is 0 I want to process the entire list
'x', but of course -0 equals 0, so it returns an empty list.
In theory I can say
On Fri, Nov 26, 2021 at 10:11 PM Rob Cliffe via Python-list
wrote:
> or, perhaps simplest, you could do
>
> for item in x[:-y or None]: # a value of None for a slice argument means
> "don't slice here"
> [do stuff]
>
This is the one I'd recommend. If you're negating a slice like this,
just a
You could evaluate y separately:
yval =
for item in x[:-yval] if yval else x:
[do stuff]
or you could do it using the walrus operator:
for item in x[:-yval] if (yval := ) else x:
[do stuff]
or, perhaps simplest, you could do
for item in x[:-y or None]: # a value of None for a slice a
Op 26/11/2021 om 10:17 schreef Frank Millman:
Hi all
In my program I have a for-loop like this -
>>> for item in x[:-y]:
... [do stuff]
'y' may or may not be 0. If it is 0 I want to process the entire list
'x', but of course -0 equals 0, so it returns an empty list.
In theory I can say
Hi all
In my program I have a for-loop like this -
>>> for item in x[:-y]:
... [do stuff]
'y' may or may not be 0. If it is 0 I want to process the entire list
'x', but of course -0 equals 0, so it returns an empty list.
In theory I can say
>>> for item in x[:-y] if y else x:
... [do
14 matches
Mail list logo