Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36461
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eweka.nl!lightspeed.eweka.nl!194.134.4.91.MISMATCH!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <msirenef@lightbird.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'tue': 0.05; 'table.': 0.07; 'api': 0.09; '(0,': 0.09; 'hooks': 0.09; 'library?': 0.09; 'pointers': 0.09; 'python:': 0.09; 'cc:addr:python-list': 0.10; "'b',": 0.16; "['a',": 0.16; 'andy': 0.16; 'appreciated!': 0.16; 'itertools': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'recipe': 0.16; 'row': 0.16; 'tried:': 0.16; 'wrote:': 0.17; 'thanks,': 0.18; 'jan': 0.18; "i'd": 0.22; 'cc:2**0': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply- To:1': 0.25; 'header:User-Agent:1': 0.26; 'dictionary': 0.29; 'end,': 0.29; "i'm": 0.29; 'url:python': 0.32; 'could': 0.32; 'print': 0.32; 'getting': 0.33; 'subject:List': 0.33; 'list': 0.35; 'something': 0.35; 'but': 0.36; 'url:org': 0.36; 'url:library': 0.36; 'subject: (': 0.36; 'turn': 0.36; 'item': 0.37; 'subject:: ': 0.38; 'url:docs': 0.38; 'received:192': 0.39; 'build': 0.39; 'received:192.168': 0.40; 'range': 0.60; 'back': 0.62; 'email addr:gmail.com': 0.63; 'more': 0.63; 'felt': 0.75; 'bank': 0.77; 'subject:this': 0.84; '2013': 0.84; 'itertools,': 0.84; 'maths': 0.84; 'vba': 0.84; 'obvious,': 0.91; 'subject:Best': 0.91 |
| Date | Tue, 08 Jan 2013 19:33:18 -0500 |
| From | Mitya Sirenef <msirenef@lightbird.net> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121011 Thunderbird/16.0.1 |
| MIME-Version | 1.0 |
| To | andydtaylor@gmail.com |
| Subject | Re: Best way to do this? List loop (matrix?) iteration |
| References | <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> |
| In-Reply-To | <25c1f151-7323-42de-833f-15639b6eff71@googlegroups.com> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Cc | python-list@python.org |
| 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.298.1357691604.2939.python-list@python.org> (permalink) |
| Lines | 46 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1357691604 news.xs4all.nl 6936 [2001:888:2000:d::a6]:57953 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:36461 |
Show key headers only | View raw
On Tue 08 Jan 2013 07:19:59 PM EST, andydtaylor@gmail.com wrote:
> Hi!
>
> I might be missing the obvious, or I may have found something more complicated than the VBA I am used to. Could it be I need to use a maths library?
>
> For a given list of k items I'd like to turn it into an k*k matrix of item pairs.
>
> List_sample = ['a', 'b', 'c']
>
> Output:
>
> aa ab ac
> ba bb bc
> ca cb cc
>
> I'd like to have 2 hooks into this process
> 1. I want the opportunity to use a value pair each time they are generated (because I need to send these to an api and get a number back to put into a temporary list or dictionary - still tbd).
> 2. I'd also like to know each time a row is completed so I can bank that temporary list to a database table. Else build one big list and do it at the end, I'm still figuring this out.
>
> #Code I've tried:
>
> stn_count = len(stn_list_short)
> for rowcount in range (0, stn_count):
> for colcount in range (0, stn_count):
> print stn_list_long[rowcount] stn_list_long[colcount]
>
> I've found itertools, tee, and product and felt I was getting warmer. I'm still looking, but any pointers would be appreciated!
>
> Thanks,
>
> Andy
>
>
You can use itertools.product("abc", repeat=2) together with itertools
recipe grouper() from the same page:
http://docs.python.org/3.3/library/itertools.html?highlight=itertools#itertools
HTH, -m
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Best way to do this? List loop (matrix?) iteration andydtaylor@gmail.com - 2013-01-08 16:19 -0800
Re: Best way to do this? List loop (matrix?) iteration Mitya Sirenef <msirenef@lightbird.net> - 2013-01-08 19:33 -0500
Re: Best way to do this? List loop (matrix?) iteration Chris Angelico <rosuav@gmail.com> - 2013-01-09 13:06 +1100
Re: Best way to do this? List loop (matrix?) iteration andydtaylor@gmail.com - 2013-01-09 15:24 -0800
Re: Best way to do this? List loop (matrix?) iteration Dave Angel <d@davea.name> - 2013-01-09 18:49 -0500
Re: Best way to do this? List loop (matrix?) iteration andydtaylor@gmail.com - 2013-01-09 15:24 -0800
csiph-web