Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'method.': 0.07; 'input,': 0.09; 'method,': 0.09; 'subject:set': 0.09; 'filename:fname piece:signature': 0.16; 'from:addr:carl': 0.16; 'it;': 0.16; 'iterable': 0.16; 'pythonic': 0.16; 'received:173.255': 0.16; 'tim,': 0.16; 'elements': 0.16; 'wrote:': 0.18; 'input': 0.22; 'header:User-Agent:1': 0.23; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'tim': 0.29; 'sets': 0.30; 'subject:list': 0.30; 'work.': 0.31; '>>>>': 0.31; 'object.': 0.31; 'python2.7': 0.31; 'lists': 0.32; 'noticed': 0.34; "i'd": 0.34; 'add': 0.35; 'set.': 0.36; "didn't": 0.36; 'useful': 0.36; 'list': 0.37; 'to:addr:python- list': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'today,': 0.61; 'received:173': 0.61; 'received:96': 0.65; 'charset:windows-1252': 0.65 Date: Thu, 30 Apr 2015 10:16:42 -0600 From: Carl Meyer User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: mixing set and list operations References: <7f1dc7d2-2f88-4b1e-b3ae-bb67ae7e0028@googlegroups.com> In-Reply-To: <7f1dc7d2-2f88-4b1e-b3ae-bb67ae7e0028@googlegroups.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="B8Q7Dq1SAOsaAbdwImtjUpCpjG5d7xp2I" X-Spam-Status: No (score -1.0): ALL_TRUSTED=-1 X-Spam-Bar: - X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1430412418 news.xs4all.nl 2916 [2001:888:2000:d::a6]:33433 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:89641 This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --B8Q7Dq1SAOsaAbdwImtjUpCpjG5d7xp2I Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable Hi Tim, On 04/30/2015 10:07 AM, Tim wrote: > I noticed this today, using Python2.7 or 3.4, and wondered if it is imp= lementation dependent: >=20 > You can use 'extend' to add set elements to a list and use 'update' to = add list elements to a set. >=20 >>>> m =3D ['one', 'two'] >>>> p =3D set(['three', 'four']) >>>> m.extend(p) >>>> m > ['one', 'two', 'four', 'three'] >=20 >>>> m =3D ['one', 'two'] >>>> p =3D set(['three', 'four']) >>>> p.update(m) >>>> p > set(['four', 'three', 'two', 'one']) >=20 >=20 > Useful if you don't care about ordering. Not sure if it's dangerous. I don't think this is surprising, nor implementation dependent, nor dangerous. Lists have an `extend()` method, sets have an `update()` method. Both of these methods take any iterable as input, they don't needlessly constrain the input to be of the same type as the base object. That's the Pythonic way to do it; I'd be surprised if it didn't work. Carl --B8Q7Dq1SAOsaAbdwImtjUpCpjG5d7xp2I Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCAAGBQJVQlVrAAoJEC0ft5FqUuEhddYP/1Ynsw5SUrKzn1IN9XTRQ9ff NjymMDohPOWpciH19xelrphOdfKxkIiQ3WARIgZu5Cg2/h01Kbwdu0fdEma491y9 Ql3i5mk1nlQW5aOUjO8uEWPzdSIdbp1x0ANXGl2MxpND7X2bHZg/V+r25GahcApv 7BGlMEcxK99kUNNo5b3ju7+FdYfrDicvE9rJ1zEJLXY63o9ul9v8mv4lO7mWjNLi +oKeIHtQrTbxfXC3AxnYSbf3GIPMyIuzHRnTUU8g/A+ZROiC/Gkh6/sxUr6w3Elx 7qS8wqBQJmRfhHYFJGDr6/wC5NmDOq1zmGoPJIE0GyatEiTve4QA3P3bQxH0bnVS NDpfJizbPIBDgCZSlP/+5UFdGS54wnuFVEXeZrCvAi+f6ao6zFo3nngw24FS70PD eCGX3fIU4xQWHwolFYruiL3Iw80MHsCilzJqbJrJnciU61lg6tR9r2t0c3LHV7gX gRPcaieD8PNQON8xNVfQnsOeWKvd7VpoE0wiGmSG9ecWBmqvHM2Jb6aV99fzk2tD oHHV8U6tkeTxhIjRfnxpUzux0Yf2R0+s1ozkmmcLiqqBH/AILLmLF15OBaBGY7J/ xBKp17AUPf+hlMyW4EtH4YDV4QkTFtOhErVdxjrEQXPbAMzSCXQ5X7GDgZ9Llzzk nU0+b54rQ2QONJFES2RQ =1k3m -----END PGP SIGNATURE----- --B8Q7Dq1SAOsaAbdwImtjUpCpjG5d7xp2I--