Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39212
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'example:': 0.03; 'subject:help': 0.07; 'fork': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'def': 0.10; '"for"': 0.16; 'dog': 0.16; 'etc...': 0.16; 'fruit': 0.16; 'itertools': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'wrote:': 0.17; '>>>': 0.18; 'import': 0.21; 'this:': 0.23; 'header:User-Agent:1': 0.26; 'header:X-Complaints-To:1': 0.28; 'this?': 0.28; 'cat': 0.29; 'cycles': 0.29; 'use?': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; 'lists': 0.31; 'gets': 0.32; 'could': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'self': 0.34; 'lists.': 0.35; 'something': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'item': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'information': 0.63; 'email addr:gmail.com': 0.63; 'hello!': 0.65; 'subject:Data': 0.65; 'pear': 0.84; 'subject:urgent': 0.91 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Peter Otten <__peter__@web.de> |
| Subject | Re: Data Tree urgent help!!!!!! |
| Date | Tue, 19 Feb 2013 13:34:40 +0100 |
| Organization | None |
| References | <4abbe91f-a57e-47de-9cf3-5b9574201c83@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="ISO-8859-1" |
| Content-Transfer-Encoding | 7Bit |
| X-Gmane-NNTP-Posting-Host | p508495be.dip.t-dialin.net |
| User-Agent | KNode/4.7.3 |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2018.1361277272.2939.python-list@python.org> (permalink) |
| Lines | 50 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1361277272 news.xs4all.nl 6910 [2001:888:2000:d::a6]:55772 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:39212 |
Show key headers only | View raw
anadionisio257@gmail.com wrote: > Hello! > I have this lists with information and I need to make a "tree" by > associating the information inside the lists. For example: > > l1 = [apple, pear] > l2 = [dog, cat] > l3 = [fork, spoon] > > And I need to make something like this: > > l4 = [apple, dog, fork] > l5 = [apple, dog, spoon] > l6= [apple, cat, fork] > l7 = [apple, cat, spoon] > l8 = [pear, dog, fork] > etc... > > How can I do this? I could use "for" cycles and "if...else" but with > larger lists it gets complicated > > Is there some simple solution that I can use? Try itertools.product(): >>> class Name(str): ... def __repr__(self): ... return self ... >>> apple, pear, dog, cat, fork, spoon = map(Name, "apple pear dog cat fork spoon".split()) >>> fruit = [apple, pear] >>> pets = [dog, cat] >>> cutlery = [fork, spoon] >>> from itertools import product >>> for item in product(fruit, pets, cutlery): ... print item ... (apple, dog, fork) (apple, dog, spoon) (apple, cat, fork) (apple, cat, spoon) (pear, dog, fork) (pear, dog, spoon) (pear, cat, fork) (pear, cat, spoon)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Data Tree urgent help!!!!!! anadionisio257@gmail.com - 2013-02-19 04:14 -0800
Re: Data Tree urgent help!!!!!! Peter Otten <__peter__@web.de> - 2013-02-19 13:34 +0100
Re: Data Tree urgent help!!!!!! Ana Dionísio <anadionisio257@gmail.com> - 2013-02-19 04:50 -0800
Re: Data Tree urgent help!!!!!! Ana Dionísio <anadionisio257@gmail.com> - 2013-02-19 04:50 -0800
Re: Data Tree urgent help!!!!!! Leo Breebaart <leo@lspace.org> - 2013-02-20 10:18 +0000
Re: Data Tree urgent help!!!!!! Peter Otten <__peter__@web.de> - 2013-02-20 11:46 +0100
Re: Data Tree urgent help!!!!!! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-20 22:01 +1100
Re: Data Tree urgent help!!!!!! Chris Angelico <rosuav@gmail.com> - 2013-02-20 22:16 +1100
Re: Data Tree urgent help!!!!!! Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-20 22:47 +1100
csiph-web