On 28/06/2021 11.57, Stefan Ram wrote:
"Michael F. Stemper" writes:
for iter in range(n):
chunkofcode
When the counter does not matter, people sometimes write "_":
for _ in range( n ):
chunkofcode
That looks like what I wanted.
Thanks!
--
Michael F. Stemper
Indians scattered o
On Wed, Sep 28, 2011 at 07:01:11PM -0400, Terry Reedy wrote:
> On 9/28/2011 5:26 PM, Ethan Furman wrote:
>
> >I don't remember if 'def' is sugar for something besides lambda.
>
> That is a bit backwards.
> lambda x: expr(x)
> is syntactic sugar for
> def (x): return expr(x)
> del
> ;-)
>
On 9/28/2011 5:26 PM, Ethan Furman wrote:
I don't remember if 'def' is sugar for something besides lambda.
That is a bit backwards.
lambda x: expr(x)
is syntactic sugar for
def (x): return expr(x)
del
;-)
--
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, Sep 28, 2011 at 3:26 PM, Ethan Furman wrote:
> I remember that 'class' is sugar for type().
>
> I don't remember if 'def' is sugar for something besides lambda.
This is something I have thought about a lot since PyCon this year. I
apologize in advance.
Since 3.0, class statements
En Wed, 28 Sep 2011 18:51:00 -0300, Chris Kaynor
escribió:
On Wed, Sep 28, 2011 at 2:37 PM, Arnaud Delobelle
wrote:
On 28 September 2011 22:26, Ethan Furman wrote:
I remember that 'class' is sugar for type().
I don't remember if 'def' is sugar for something besides lambda.
Any clue
On Wed, Sep 28, 2011 at 2:37 PM, Arnaud Delobelle wrote:
> On 28 September 2011 22:26, Ethan Furman wrote:
>> I remember that 'class' is sugar for type().
>>
>> I don't remember if 'def' is sugar for something besides lambda.
>>
>> Any clues for me? Heck, I'll even be grateful for outright a
On 28 September 2011 22:26, Ethan Furman wrote:
> I remember that 'class' is sugar for type().
>
> I don't remember if 'def' is sugar for something besides lambda.
>
> Any clues for me? Heck, I'll even be grateful for outright answers!
It's not really sugar. But I think you mean something l
On Wed, Sep 28, 2011 at 3:26 PM, Ethan Furman wrote:
> I remember that 'class' is sugar for type().
>
> I don't remember if 'def' is sugar for something besides lambda.
>
> Any clues for me? Heck, I'll even be grateful for outright answers!
If you mean is there a way to create functions usin
In article
<16ea4848-db0c-489a-968c-ca40700f5...@m5g2000prh.googlegroups.com>,
gc wrote:
> I frequently need to initialize several variables to the same
> value, as I'm sure many do. Sometimes the value is a constant, often
> zero; sometimes it's more particular, such as defaultdict(list). I us
On Aug 3, 2:45 am, gc wrote:
> Hi everyone! Longtime lurker, hardly an expert, but I've been using
> Python for various projects since 2007 and love it.
>
> I'm looking for either (A) suggestions on how to do a very common
> operation elegantly and Pythonically, or (B) input on whether my
> propos
:
Off on a tangent ...
On 16 August 2011 20:14, gc wrote:
>
> Let me address one smell from my particular example, which may be the
> one you're noticing. If I needed fifty parallel collections I would
> not use separate variables; I've coded a ghastly defaultdefaultdict
> just for this purpose,
gc wrote:
Target lists using comma separation are great, but they don't work
very well for this task. What I want is something like
a,b,c,d,e = *dict()
This isn't going to happen. From all the discussion so far I think your
best solution is a simple helper function (not tested):
def repeat
gc wrote:
> Maybe this is more visibly convenient with a complex class, like
>
> x, y, z = *SuperComplexClass(param1, param2, kwparam = "3", ...)
>
> where you need three separate objects but don't want to duplicate the
> class call (for obvious copy-paste reasons) and where bundling it in a
> l
On Wed, Aug 17, 2011 at 5:55 PM, MRAB wrote:
> x, y, z = lazy copies(SuperComplexClass(param1, etc, ...))
>
This assumes that you can construct it once and then copy it reliably,
which may mean that the class implement copying correctly. It also
wouldn't work with:
a, b, c, d = *random.randint(1
On 17/08/2011 10:26, gc wrote:
On Aug 17, 3:13 am, Chris Angelico wrote:
Minor clarification: You don't want to initialize them to the same
value, which you can do already:
a=b=c=d=e=dict()
Right. Call the proposed syntax the "instantiate separately for each
target" operator. (It can be pr
The issue behind this thread is that for immutable objects, binding to n
copies has the same effect as n bindings to one object (so one does not
really have to know which one is doing), whereas the two are different
for mutable objects (so one does have to know). In short, identity
matters for
On Aug 17, 5:45 am, Chris Angelico wrote:
(snip)
> > Right. Call the proposed syntax the "instantiate separately for each
> > target" operator.
>
(snip)
> It might just
> as easily be some other function call; for instance:
>
> head1,head2,head3=file.readline()
Hm--that's interesting! OK, call it
On Wed, Aug 17, 2011 at 10:26 AM, gc wrote:
> On Aug 17, 3:13 am, Chris Angelico wrote:
>
>> Minor clarification: You don't want to initialize them to the same
>> value, which you can do already:
>>
>> a=b=c=d=e=dict()
>
> Right. Call the proposed syntax the "instantiate separately for each
> tar
On Aug 17, 3:13 am, Chris Angelico wrote:
> Minor clarification: You don't want to initialize them to the same
> value, which you can do already:
>
> a=b=c=d=e=dict()
Right. Call the proposed syntax the "instantiate separately for each
target" operator. (It can be precisely defined as a * on th
On Wed, Aug 17, 2011 at 1:14 AM, gc wrote:
> Perfectly reasonable request! Maybe there aren't as many cases when
> multiple variables need to be initialized to the same value as I think
> there are.
>
Minor clarification: You don't want to initialize them to the same
value, which you can do alrea
On 17/08/2011 01:14, gc wrote:
On Aug 16, 4:39 pm, "Martin P. Hellwig"
wrote:
On 03/08/2011 02:45, gc wrote:
a,b,c,d,e = *dict()
where * in this context means something like "assign separately to
all.
. . . it has a certain code smell to it.
I would love to see an example where you wo
On Aug 16, 4:39 pm, "Martin P. Hellwig"
wrote:
> On 03/08/2011 02:45, gc wrote:
>
>
> > a,b,c,d,e = *dict()
>
> > where * in this context means something like "assign separately to
> > all.
> . . . it has a certain code smell to it.
> I would love to see an example where you would need such a
On 03/08/2011 02:45, gc wrote:
a,b,c,d,e = *dict()
where * in this context means something like "assign separately to
all.
Any thoughts? Thanks!
Well got a thought but I am afraid it is the opposite of helpful in the
direct sense. So if you don't want to hear it skip it :-)
Although I c
Thanks for all the discussion on this. Very illuminating. Sorry for
the long delay in responding--deadlines intervened.
I will use the list comprehension syntax for the foreseeable future.
Tim, I agree with you about the slurping in final position--it's
actually quite surprising. As I'm sure you
On 08/03/2011 03:36 AM, Katriel Cohn-Gordon wrote:
On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano wrote:
a, b, c, d, e = [dict() for i in range(5)]
I think this is good code -- if you want five different dicts,
then you should call dict five times. Otherwise Python will
magically call your ex
On 08/03/2011 03:25 AM, Steven D'Aprano wrote:
gc wrote:
Target lists using comma separation are great, but they don't work
very well for this task. What I want is something like
a,b,c,d,e = *dict()
a, b, c, d, e = [dict() for i in range(5)]
Unfortunately there is no way of doing so withou
On Wed, Aug 3, 2011 at 9:25 AM, Steven D'Aprano <
steve+comp.lang.pyt...@pearwood.info> wrote:
> gc wrote:
>
> > Target lists using comma separation are great, but they don't work
> > very well for this task. What I want is something like
> >
> > a,b,c,d,e = *dict()
>
> a, b, c, d, e = [dict() for
gc wrote:
Alternatively, is there a version of iterable multiplication that
creates new objects rather than just copying the reference?
You can use a list comprehension:
a, b, c, d, e = [dict() for i in xrange(5)]
or a generator expression:
a, b, c, d, e = (dict() for i in xrange(5))
-
gc wrote:
> Target lists using comma separation are great, but they don't work
> very well for this task. What I want is something like
>
> a,b,c,d,e = *dict()
a, b, c, d, e = [dict() for i in range(5)]
Unfortunately there is no way of doing so without counting the assignment
targets. While sl
On Wed, Aug 3, 2011 at 2:45 AM, gc wrote:
> Anyway, I frequently need to initialize several variables to the same
> value, as I'm sure many do. Sometimes the value is a constant, often
> zero; sometimes it's more particular, such as defaultdict(list). I use
> dict() below.
If it's an immutable va
30 matches
Mail list logo