Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #102685
| Path | csiph.com!feeder.erje.net!2.eu.feeder.erje.net!newsfeed.freenet.ag!87.79.20.101.MISMATCH!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Set Operations on Dicts |
| Date | Mon, 8 Feb 2016 09:12:45 -0700 |
| Lines | 19 |
| Message-ID | <mailman.106.1454948013.2317.python-list@python.org> (permalink) |
| References | <mailman.86.1454925476.2317.python-list@python.org> <n9a2jk$9s$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de X/oe+KnQh/p2PLJmfxnKYQZpSuRiH9Pf3Ye5mA5XOY3g== |
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.034 |
| X-Spam-Evidence | '*H*': 0.93; '*S*': 0.00; 'dict': 0.09; '2016': 0.16; 'intersection': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'set-like': 0.16; "{'a':": 0.16; 'wrote:': 0.16; 'am,': 0.23; 'feb': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'message-id:@mail.gmail.com': 0.27; 'dictionary': 0.29; 'expose': 0.29; 'received:google.com': 0.35; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'say': 0.37; 'received:209.85.213': 0.37; 'difference': 0.38; 'received:209': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'to:name:python': 0.84; 'subject:Set': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=1c05j8X5hdl9hz1b2GNnjqQ6ssNqF3+1nuPhU5kYjq4=; b=KWC/fBk2YP9SeAwUDVd4VEBpvl9H86Js9aF2aH/HrisKL96BTKfSzWqe76NgVAeF6i RUUnvH+u9L6vkJwgLO3czfWCdDYDHgMQO4PJ/fhgZLiPWAVBZpELyto9V5/Yb2T2AoDb +QNAm3B35vz7wjkG6WgSBfZlCW9CNEUnWLojplxDhXjHhIyu+HRMvAy++//V66bGB+Bg 0cK34r7YR1rxvcAX46GBX2twXIvbLSpM6Nj4xx9vQKBkC76vzac09oyOfGQuAkT3nJWd fNjozjgEgyRj6m6JzsipD12OT7nFI8mENHpNvfy+tn9LuGB2gXiirSepI0usEvtzEs6D DQdg== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=1c05j8X5hdl9hz1b2GNnjqQ6ssNqF3+1nuPhU5kYjq4=; b=IE5JhtB7GOf+h7gXmmY3E/9GpnNcE3YQaPZsuBgTXbXyblo+HJR+mbaB6V2FyxW0MA b0tgNY5jbC12iku1G1wpfptgPZvC7yjdGncd65HjAA60LfE5OoHu7XsWJQU1KGcPoXR6 OFSq87UPXvp5GVmZSLKqFgBC4m2sX9f3Q3HpqhG4jRrhEGP/k1ZFzfFypsyuAolzz93G g7r02sm0xZKF1HoBSo9D8SFaeqwSVJ8pF9z8Zio7XIR9GE+T90iXhkOjYtdXiZiuy7JG BEjPO16FUSUsoa9Y0joi/eoLEPHKp3Rk2XdL4QSAqJ8Z6MYUvrOKOLCWWznq2vmmCyYi NMcg== |
| X-Gm-Message-State | AG10YOR5Jnkp9w+whT7UQq9Kd2gZvS/jOAo6jkh4Yd+TFi2R/M/hvBN1oAnK1IyerJJ+2M5rJCTiuWj8lgpcFg== |
| X-Received | by 10.50.138.76 with SMTP id qo12mr24744637igb.85.1454948005188; Mon, 08 Feb 2016 08:13:25 -0800 (PST) |
| In-Reply-To | <n9a2jk$9s$1@dont-email.me> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.21rc2 |
| 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> |
| Xref | csiph.com comp.lang.python:102685 |
Show key headers only | View raw
On Mon, Feb 8, 2016 at 5:47 AM, Grobu <snailcoder@retrosite.invalid> wrote:
> You can use dictionary comprehension :
>
> Say :
> dict1 = {'a': 123, 'b': 456}
> set1 = {'a'}
>
> intersection :
>>>> { key:dict1[key] for key in dict1 if key in set1 }
> {'a': 123}
>
> difference :
>>>> { key:dict1[key] for key in dict1 if not key in set1 }
> {'b': 456}
dict does already expose set-like views. How about:
{k: d[k] for k in d.keys() & s} # d & s
{k: d[k] for k in d.keys() - s} # d - s
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Set Operations on Dicts Marco Kaulea <marco.kaulea@gmail.com> - 2016-02-08 10:56 +0100
Re: Set Operations on Dicts Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-02-08 14:17 +0200
Re: Set Operations on Dicts Marco Kaulea <marco.kaulea@gmail.com> - 2016-02-08 13:33 +0100
Re: Set Operations on Dicts Matt Wheeler <m@funkyhat.org> - 2016-02-08 13:32 +0000
Re: Set Operations on Dicts Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-02-08 16:02 +0200
Re: Set Operations on Dicts Random832 <random832@fastmail.com> - 2016-02-08 09:52 -0500
Re: Set Operations on Dicts Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-02-08 17:05 +0200
Re: Set Operations on Dicts Grobu <snailcoder@retrosite.invalid> - 2016-02-08 13:47 +0100
Re: Set Operations on Dicts Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-08 09:12 -0700
Re: Set Operations on Dicts Grobu <snailcoder@retrosite.invalid> - 2016-02-09 08:21 +0100
Re: Set Operations on Dicts Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-09 08:14 -0700
csiph-web