On Thu, Sep 1, 2022 at 9:16 AM Chris Angelico wrote:
> On Fri, 2 Sept 2022 at 02:10, James Tsai wrote:
> >
> > Hello,
> >
> > I find it very useful if I am allowed to define new local variables in a
> list comprehension. For example, I wish to have something like
> > [(x, y) for x in range(10) f
在 2022年9月2日星期五 UTC+2 00:17:23, 写道:
> On 02Sep2022 07:01, Chris Angelico wrote:
> >On Fri, 2 Sept 2022 at 06:55, James Tsai wrote:
> >> No but very often when I have written a neat list/dict/set
> >> comprehension, I find it very necessary
> >> to define local variable(s) to make it more clear
Dumb question. Your y is purely a function of x. So create an f(x) where
you want your y. It probably can even be anonymous inline. I mean your
return values of (x, y) would be (x, f(x)) ...
On Thu, Sep 1, 2022, 5:04 PM Chris Angelico wrote:
> On Fri, 2 Sept 2022 at 06:55, James Tsai wrote:
> >
On 02Sep2022 07:01, Chris Angelico wrote:
>On Fri, 2 Sept 2022 at 06:55, James Tsai wrote:
>> No but very often when I have written a neat list/dict/set
>> comprehension, I find it very necessary
>> to define local variable(s) to make it more clear and concise. Otherwise I
>> have to break it d
On 2022-09-01 13:33:16 -0700, James Tsai wrote:
> 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > On 9/1/22, James Tsai wrote:
> > >
> > > I find it very useful if I am allowed to define new local variables in a
> > > list comprehension. For example, I wish to have something like
> > > [(x, y) for x in
On Fri, 2 Sept 2022 at 06:55, James Tsai wrote:
>
> 在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> > On 9/1/22, James Tsai wrote:
> > >
> > > I find it very useful if I am allowed to define new local variables in a
> > > list comprehension. For example, I wish to have something like
> > > [(x, y) for x in
在 2022年9月1日星期四 UTC+2 18:16:03, 写道:
> On Fri, 2 Sept 2022 at 02:10, James Tsai wrote:
> >
> > Hello,
> >
> > I find it very useful if I am allowed to define new local variables in a
> > list comprehension. For example, I wish to have something like
> > [(x, y) for x in range(10) for y := x **
在 2022年9月1日星期四 UTC+2 18:34:36, 写道:
> On 9/1/22, James Tsai wrote:
> >
> > I find it very useful if I am allowed to define new local variables in a
> > list comprehension. For example, I wish to have something like
> > [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> > [(x, y) f
way to write it already. Your working version is, to me,
> clearer that the ones you want to be able to write.
>
> --
> Ben.
By local variable definition I mean binding a variable to a single value, so it
doesn't include giving an iterable that a variable can take values iterat
On 9/1/22, James Tsai wrote:
>
> I find it very useful if I am allowed to define new local variables in a
> list comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
>
On Fri, 2 Sept 2022 at 02:10, James Tsai wrote:
>
> Hello,
>
> I find it very useful if I am allowed to define new local variables in a list
> comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) wit
James Tsai writes:
> I find it very useful if I am allowed to define new local variables in
> a list comprehension. For example, I wish to have something like
> [(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
> [(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
>
> For now
Hello,
I find it very useful if I am allowed to define new local variables in a list
comprehension. For example, I wish to have something like
[(x, y) for x in range(10) for y := x ** 2 if x + y < 80], or
[(x, y) for x in range(10) with y := x ** 2 if x + y < 80].
For now this functionality can
On Mon, 01 Mar 2010 18:07:17 -, Raphael Mayoraz
wrote:
Thanks for your answer.
However, your solution changes the key name in the dictionary.
That's not what I want I need to do. What I want is to define a new
variable which name is define as a string: 'myPrefx' + key. In the
example
I
On 3/1/2010 1:07 PM, Raphael Mayoraz wrote:
John Posner wrote:
On 2/26/2010 6:32 PM, Raphael Mayoraz wrote:
Hello,
I'd like to define variables with some specific name that has a common
prefix.
Something like this:
varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
for key, value in varDic.iter
John Posner wrote:
On 2/26/2010 6:32 PM, Raphael Mayoraz wrote:
Hello,
I'd like to define variables with some specific name that has a common
prefix.
Something like this:
varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
for key, value in varDic.iteritems():
'myPrefix' + key = value
No trick
On 27 Feb 2010 03:33:57 GMT Steven D'Aprano
wrote:
> exec "'myPrefix_turquoise' = 42"
>
Not quite:
In [1]: exec "'myPrefix_turquoise' = 42"
File "", line 1
SyntaxError: can't assign to literal (, line 1)
I think you meant:
exec
Steven D'Aprano wrote:
for key, value in varDic.iteritems():
varDic['myPrefix_' + key] = value
del varDic[key]
Watch out if any of the existing values already startswith 'myPrefix'
You can end up with trouble just as confusing as if 'myPrefix' is an
empty string
DaveA
--
http:/
On Fri, 26 Feb 2010 15:32:27 -0800, Raphael Mayoraz wrote:
> Hello,
>
> I'd like to define variables with some specific name that has a common
> prefix.
> Something like this:
>
> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
> for key, value in varDic.iteritems():
> 'myPrefix' + key = va
On 2/26/2010 10:20 PM, Steven D'Aprano wrote:
On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote:
On 2/26/2010 6:32 PM, Raphael Mayoraz wrote:
Hello,
I'd like to define variables with some specific name that has a common
prefix.
Something like this:
varDic = {'red': 'a', 'green': 'b', 'bl
On Fri, 26 Feb 2010 20:15:16 -0500, John Posner wrote:
> On 2/26/2010 6:32 PM, Raphael Mayoraz wrote:
>> Hello,
>>
>> I'd like to define variables with some specific name that has a common
>> prefix.
>> Something like this:
>>
>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'} for key, value in
>
On 2/26/2010 6:32 PM, Raphael Mayoraz wrote:
Hello,
I'd like to define variables with some specific name that has a common
prefix.
Something like this:
varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
for key, value in varDic.iteritems():
'myPrefix' + key = value
No trick, just swap a new ke
On Fri, Feb 26, 2010 at 6:22 PM, Alf P. Steinbach wrote:
> * Raphael Mayoraz:
>
>> Hello,
>>
>>
>> I'd like to define variables with some specific name that has a common
>> prefix.
>> Something like this:
>>
>> varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
>> for key, value in varDic.iteritems
* Raphael Mayoraz:
Hello,
I'd like to define variables with some specific name that has a common
prefix.
Something like this:
varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
for key, value in varDic.iteritems():
'myPrefix' + key = value
I know this is illegal, but there must be a trick s
On Fri, 26 Feb 2010 23:32:27 -, Raphael Mayoraz
wrote:
I'd like to define variables with some specific name that has a common
prefix.
Why?
No seriously, how do you think this is going to solve whatever problem you
clearly think it will solve?
--
Rhodri James *-* Wildebeeste Herder
Hello,
I'd like to define variables with some specific name that has a common
prefix.
Something like this:
varDic = {'red': 'a', 'green': 'b', 'blue': 'c'}
for key, value in varDic.iteritems():
'myPrefix' + key = value
I know this is illegal, but there must be a trick somewhere.
Thanks,
"Gerhard Fiedler" <[EMAIL PROTECTED]> wrote:
8<-
| I'm not sure where you're trying to go. I think that most people (and even
| Bruno, who argued this issue most strongly) call Python variables
| "variables" every now and then, or maybe even usually. But it was hel
27 matches
Mail list logo