Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #99016
| X-Received | by 10.107.185.195 with SMTP id j186mr5279666iof.15.1447891538269; Wed, 18 Nov 2015 16:05:38 -0800 (PST) |
|---|---|
| X-Received | by 10.50.142.66 with SMTP id ru2mr331020igb.3.1447891538213; Wed, 18 Nov 2015 16:05:38 -0800 (PST) |
| Path | csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!i2no5033677igv.0!news-out.google.com!l1ni1906igd.0!nntp.google.com!i2no5033671igv.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.lang.python |
| Date | Wed, 18 Nov 2015 16:05:37 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=50.100.117.144; posting-account=SZ_svQkAAACWRFG2bDA-zgq8ILyl4-vo |
| NNTP-Posting-Host | 50.100.117.144 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <3f1eecc8-e23d-4f86-abf8-38044939d085@googlegroups.com> (permalink) |
| Subject | Could you explain why the following generates 4 same elements list? |
| From | fl <rxjwg98@gmail.com> |
| Injection-Date | Thu, 19 Nov 2015 00:05:38 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.lang.python:99016 |
Show key headers only | View raw
Hi,
I cannot reason out why the code:
////////
def mpl():
return [lambda x : i * x for i in range(4)]
print [m(2) for m in mpl()]
/////////
has result:
[6, 6, 6, 6]
I have tried to simplify the above code to an easy understanding form,
but fails. Either the modified code does not work, or it does not show
relation to the original code.
Could you explore it a little for me to understand it easier?
Thanks in advance.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Could you explain why the following generates 4 same elements list? fl <rxjwg98@gmail.com> - 2015-11-18 16:05 -0800 Re: Could you explain why the following generates 4 same elements list? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-18 17:47 -0700 Re: Could you explain why the following generates 4 same elements list? dieter <dieter@handshake.de> - 2015-11-19 08:27 +0100
csiph-web