Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #67382
| Path | csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '(python': 0.07; 'elements.': 0.07; '*is*': 0.09; 'key.': 0.09; 'literal': 0.09; 'toss': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; "wouldn't": 0.14; 'change;': 0.16; 'dict': 0.16; 'dictionaries': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'hmm.': 0.16; 'instead).': 0.16; 'key):': 0.16; 'keys.': 0.16; 'notation': 0.16; 'set()': 0.16; 'subclass': 0.16; 'subject:dictionaries': 0.16; 'x["test"]': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'integer': 0.24; "shouldn't": 0.24; 'cc:2**0': 0.24; 'switch': 0.26; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'sets': 0.30; 'message- id:@mail.gmail.com': 0.30; 'that.': 0.31; '>>>>': 0.31; 'assert': 0.31; 'keys': 0.31; 'writes:': 0.31; 'class': 0.32; 'skip:_ 10': 0.34; 'could': 0.34; "can't": 0.35; 'received:google.com': 0.35; 'add': 0.35; 'false': 0.36; 'too': 0.37; 'mapping': 0.38; 'does': 0.39; 'skip:x 10': 0.40; 'remove': 0.60; 'john': 0.61; 'simply': 0.61; '26,': 0.68; 'periodically': 0.68; 'actually,': 0.84; "it'd": 0.84; 'pike': 0.84; 'sets,': 0.84; 'to:none': 0.92 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=cmKIv65ABICi14d6vBIDhsQzM85U20OtRGHRjvBFxYc=; b=FjQYwZw1ro7YzsID6MHsWUbbVpCbvSH0bbL+5CGTFWYi/NsZPuRLoPnWnu1X8UCMeo pH9i0vf184BHIFHX+HTcwpfJd2i8O/yFuZc62bZH+yam7+903mvgo9nxaSTttfYklymL gI+WGwQ8DRTQZxlz+gGpcG5H9CXJJreb3uTBalP91w8bECi3ONZPilqvhPNzeXhA++eX BmWSVBslqcJAybXotVeZQI9gy8+ixvYXa9/lBelSSz99TwRraq+FbqgOypIVMg9w+o8w Xam/6Or3f+/JdYt14YaektZ+bjFvnv1zCr8CkUUlY+s/AHqAOsL54CwzJMhH3Or9DM6H NCkA== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.33.106 with SMTP id q10mr71480pbi.132.1393712965423; Sat, 01 Mar 2014 14:29:25 -0800 (PST) |
| In-Reply-To | <leivbq$hs0$1@reader1.panix.com> |
| References | <G57Pu.24239$Th2.4990@tornado.fastwebnet.it> <leivbq$hs0$1@reader1.panix.com> |
| Date | Sun, 2 Mar 2014 09:29:25 +1100 |
| Subject | Re: intersection, union, difference, symmetric difference for dictionaries |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.7543.1393712974.18130.python-list@python.org> (permalink) |
| Lines | 53 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1393712974 news.xs4all.nl 2849 [2001:888:2000:d::a6]:46563 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:67382 |
Show key headers only | View raw
On Wed, Feb 26, 2014 at 7:44 AM, John Gordon <gordon@panix.com> wrote:
> In <G57Pu.24239$Th2.4990@tornado.fastwebnet.it> mauro <mauro@gmail.com> writes:
>
>> - Dictionaries and sets are both accessed by key
>
> As far as I have used sets, they are not accessed by key.
>
>>>> x = set([1, 2, 'buckle my shoe'])
>>>> x
> set([1, 2, 'buckle my shoe'])
>>>> 1 in x
> True
>>>> 5 in x
> False
>>> x = {1:3, 2:4, 'buckle my shoe':'spamming the door'}
>>> x
{1: 3, 2: 4, 'buckle my shoe': 'spamming the door'}
>>> 1 in x
True
>>> 5 in x
False
A dict does the exact same thing with its keys as a set does with its
elements. Actually, one of the things that periodically trips me up
when I switch from Pike to Python is that a Python set can't be used
like this:
>>> x = set()
>>> x["test"] = 1
>>> x["foo"] = 1
>>> assert x == {"test","foo"}
Instead, I have to use x.add("test"). In Pike, I can treat a set as if
it were a mapping where every value is simply the integer 1 (Python
could use True instead). Setting it to any truthy value would add it,
setting to any falsy value would remove it. This wouldn't be a huge
change; it certainly wouldn't fundamentally change the set type -
because it *is* working with keys.
Hmm. Actually, it shouldn't be too hard to subclass and add that. Lessee.
class set(set):
def __setitem__(self, key, state):
if state: self.add(key)
else: self.remove(key)
def __getitem__(self, key):
return key in self
I might need to toss that into site.py or something. It'd work as long
as I don't use set literal notation anywhere.
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
intersection, union, difference, symmetric difference for dictionaries mauro <mauro@gmail.com> - 2014-02-25 20:32 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Nick Timkovich <prometheus235@gmail.com> - 2014-02-25 14:37 -0600
Re: intersection, union, difference, symmetric difference for dictionaries Skip Montanaro <skip@pobox.com> - 2014-02-25 14:40 -0600
Re: intersection, union, difference, symmetric difference for dictionaries Peter Otten <__peter__@web.de> - 2014-02-25 21:53 +0100
Re: intersection, union, difference, symmetric difference for dictionaries Peter Otten <__peter__@web.de> - 2014-02-25 21:58 +0100
Re: intersection, union, difference, symmetric difference for dictionaries Tim Chase <python.list@tim.thechases.com> - 2014-02-25 15:03 -0600
Re: intersection, union, difference, symmetric difference for dictionaries Duncan Booth <duncan.booth@invalid.invalid> - 2014-02-25 22:21 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Tim Chase <tim@thechases.com> - 2014-02-25 16:35 -0600
Re: intersection, union, difference, symmetric difference for dictionaries Tim Chase <python.list@tim.thechases.com> - 2014-02-25 16:36 -0600
Re: intersection, union, difference, symmetric difference for dictionaries Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2014-02-25 22:58 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-25 23:10 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Tim Chase <python.list@tim.thechases.com> - 2014-02-25 20:21 -0600
Re: intersection, union, difference, symmetric difference for dictionaries Ben Finney <ben+python@benfinney.id.au> - 2014-02-26 08:27 +1100
Re:intersection, union, difference, symmetric difference for dictionaries Dave Angel <davea@davea.name> - 2014-02-25 16:35 -0500
Re: intersection, union, difference, symmetric difference for dictionaries Peter Otten <__peter__@web.de> - 2014-02-25 22:54 +0100
Re: intersection, union, difference, symmetric difference for dictionaries mauro <mauro@gmail.com> - 2014-02-25 22:02 +0000
Re: intersection, union, difference, symmetric difference for dictionaries mauro <mauro@gmail.com> - 2014-02-25 22:03 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Tim Chase <python.list@tim.thechases.com> - 2014-02-25 16:10 -0600
Re: intersection, union, difference, symmetric difference for dictionaries mauro <mauro@gmail.com> - 2014-02-25 22:11 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-25 22:35 +0000
Re: intersection, union, difference, symmetric difference for dictionaries MRAB <python@mrabarnett.plus.com> - 2014-02-25 23:07 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-26 00:37 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Ben Finney <ben+python@benfinney.id.au> - 2014-02-26 10:14 +1100
Re: intersection, union, difference, symmetric difference for dictionaries MRAB <python@mrabarnett.plus.com> - 2014-02-25 23:25 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Grant Edwards <invalid@invalid.invalid> - 2014-02-25 20:44 +0000
Re: intersection, union, difference, symmetric difference for dictionaries John Gordon <gordon@panix.com> - 2014-02-25 20:44 +0000
Re: intersection, union, difference, symmetric difference for dictionaries Chris Angelico <rosuav@gmail.com> - 2014-03-02 09:29 +1100
Re: intersection, union, difference, symmetric difference for dictionaries albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-03-15 17:24 +0000
csiph-web