Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #84971
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <jsf80238@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.025 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'subject:two': 0.07; 'cc:addr:python-list': 0.11; 'itertools': 0.16; 'skip:[ 40': 0.16; 'subject:based': 0.16; 'subject:key': 0.16; 'import': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'possibility': 0.29; 'message-id:@mail.gmail.com': 0.30; 'subject:per': 0.31; 'lists': 0.32; 'another': 0.32; 'subject:from': 0.34; 'equal': 0.35; 'subject:lists': 0.35; 'received:google.com': 0.35; 'two': 0.37; 'skip:[ 10': 0.38; '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=pe7qeLr3BegMiBslJVQ//9IEHXPuO7rdlCKOQMREWBk=; b=qZ8V5O5qOvFo/n/fINZhshx6A718gIA/CTCAAXwaNhtTvx//kR/TmgRDJx85H/yv7c 7nB8XUV9X7BnrISnoDVMF7eumzZXLZJdCJe+shPpCklCzgYy0hELrjAR3yIIW5XxUIRm A77G9ywi+vrdLg/0IbE82CSeFpm6JWeAex62j9sqGZPbhDTsgbGqK5NNMKNhTnNqakdK 9uDlxgQtQsUh0Zn2EmL3ZSTEXsAgmayfSand8X3f6j/LtvKehObc0DHES7b43ujbzdnI joLt/sQPa/mvrPpEUILtsSG3E+SIV0kUxFJXGKrhrGPIVq/hmwqa5US3uSVi3mm/WMkH 5LTQ== |
| MIME-Version | 1.0 |
| X-Received | by 10.180.82.137 with SMTP id i9mr10656571wiy.38.1422758328804; Sat, 31 Jan 2015 18:38:48 -0800 (PST) |
| In-Reply-To | <0dddee06-233b-436a-be48-3c16e62c1718@googlegroups.com> |
| References | <0dddee06-233b-436a-be48-3c16e62c1718@googlegroups.com> |
| Date | Sat, 31 Jan 2015 19:38:48 -0700 |
| Subject | Re: Create dictionary based of x items per key from two lists |
| From | Jason Friedman <jsf80238@gmail.com> |
| Cc | python-list <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.18344.1422758329.18130.python-list@python.org> (permalink) |
| Lines | 29 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1422758329 news.xs4all.nl 2934 [2001:888:2000:d::a6]:59621 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:84971 |
Show key headers only | View raw
> I have two lists
>
> l1 = ["a","b","c","d","e","f","g","h","i","j"]
> l2 = ["aR","bR","cR"]
>
> l2 will always be smaller or equal to l1
>
> numL1PerL2 = len(l1)/len(l2)
>
> I want to create a dictionary that has key from l1 and value from l2 based on numL1PerL2
>
> So
>
> {
> a:aR,
> b:aR,
> c:aR,
> d:bR,
> e:bR,
> f:bR,
> g:cR,
> h:cR,
> i:cR,
> j:cR
> }
Another possibility is:
import itertools
my_dict = {x:y for x,y in zip(list1, itertools.cycle(list2))}
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Create dictionary based of x items per key from two lists rajanbond@gmail.com - 2015-01-30 18:27 -0800
Re: Create dictionary based of x items per key from two lists Chris Angelico <rosuav@gmail.com> - 2015-01-31 13:38 +1100
Re: Create dictionary based of x items per key from two lists Jason Friedman <jsf80238@gmail.com> - 2015-01-31 19:38 -0700
Re: Create dictionary based of x items per key from two lists rajanbond@gmail.com - 2015-02-02 10:48 -0800
Re: Create dictionary based of x items per key from two lists rajanbond@gmail.com - 2015-02-02 11:00 -0800
Re: Create dictionary based of x items per key from two lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-01 03:06 +0000
Re: Create dictionary based of x items per key from two lists Chris Angelico <rosuav@gmail.com> - 2015-02-01 14:22 +1100
Re: Create dictionary based of x items per key from two lists Grant Edwards <invalid@invalid.invalid> - 2015-02-01 18:14 +0000
Re: Create dictionary based of x items per key from two lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-01 18:49 +0000
Re: Create dictionary based of x items per key from two lists mm0fmf <none@mailinator.com> - 2015-02-01 18:52 +0000
Re: Create dictionary based of x items per key from two lists Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-01 12:36 -0700
Re: Create dictionary based of x items per key from two lists wxjmfauth@gmail.com - 2015-02-02 23:13 -0800
Re: Create dictionary based of x items per key from two lists Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-02-01 20:28 +0000
Re: Create dictionary based of x items per key from two lists Chris Angelico <rosuav@gmail.com> - 2015-02-02 07:33 +1100
Re: Create dictionary based of x items per key from two lists Ian Kelly <ian.g.kelly@gmail.com> - 2015-02-01 11:51 -0700
csiph-web