Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #39150
| 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 | <msirenef@lightbird.net> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'elements.': 0.05; 'python': 0.09; 'docs.': 0.09; 'if,': 0.09; 'iterate': 0.09; 'python:': 0.09; 'themselves,': 0.09; 'tuple': 0.09; '"2":': 0.16; 'col': 0.16; 'dictionary.': 0.16; 'nevertheless': 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; 'tup': 0.16; 'tuple):': 0.16; 'wrote:': 0.17; 'exists': 0.17; 'keys': 0.22; 'sorry,': 0.22; 'tuples': 0.22; "i'd": 0.22; 'this:': 0.23; 'thus': 0.24; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'values': 0.26; 'skip:( 20': 0.28; 'dictionary': 0.29; 'wrap': 0.29; "i'm": 0.29; 'could': 0.32; 'to:addr:python-list': 0.33; 'pm,': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'anything': 0.36; 'subject:with': 0.36; 'data': 0.37; 'subject:: ': 0.38; 'easier': 0.38; 'performance': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'google': 0.39; 'received:192.168': 0.40; 'your': 0.60; 'most': 0.61; 'first': 0.61; 'skip:n 10': 0.63; 'grab': 0.64; 'dict,': 0.84; 'judges': 0.84; 'say:': 0.84; 'convinced': 0.93 |
| Date | Mon, 18 Feb 2013 20:11:05 -0500 |
| From | Mitya Sirenef <msirenef@lightbird.net> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130106 Thunderbird/17.0.2 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Dictionaries with tuples or tuples of tuples |
| References | <c8abdc96-a47c-462a-9d6e-fcbaad1102fe@googlegroups.com> |
| In-Reply-To | <c8abdc96-a47c-462a-9d6e-fcbaad1102fe@googlegroups.com> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| 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.1987.1361236273.2939.python-list@python.org> (permalink) |
| Lines | 40 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1361236273 news.xs4all.nl 6899 [2001:888:2000:d::a6]:38189 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:39150 |
Show key headers only | View raw
On 02/18/2013 07:52 PM, Jon Reyes wrote:
> So I have a dictionary and the key is a number. The values are either a single tuple or a tuple of
tuples. Is there a better way to go about accessing the values of the
dictionary? All the tuples contain four elements.
>
> So say:
> col = {"1": (0,1,2,3): "2": ((0,1,2,3),(2,3,4,5))}
>
> Then to access the values of the tuple I'd do this:
>
> for key,value in col.iteritems():
> if isinstance(value[0], tuple):
> #iterate through the tuples of a tuple
> else:
> #iterate through the tuple
>
> At first I was thinking that I could just put the same keys with just
single tuples on a dictionary but only one tuple exists when I iterate
through the dictionary. I'm sorry, I'm really new at Python and I just
grab anything I can when I need it from Google and the Python docs.
It would be easier to process if, when adding a single tuple
to the dict, you could wrap it inside a tuple: (mytup,)
If your data set is not very large and you don't mind the
slight performance hit, you can simplify processing step:
for k,v in col.iteritems():
if not isinstance(v[0], tuple):
v = (v,)
for tup in v: ...
--
Lark's Tongue Guide to Python: http://lightbird.net/larks/
Although the most acute judges of the witches and even the witches
themselves, were convinced of the guilt of witchery, the guilt nevertheless
was non-existent. It is thus with all guilt. Friedrich Nietzsche
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 16:52 -0800
Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 20:11 -0500
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:19 -0800
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:19 -0800
Re: Dictionaries with tuples or tuples of tuples Roy Smith <roy@panix.com> - 2013-02-18 20:17 -0500
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:20 -0800
Re: Dictionaries with tuples or tuples of tuples Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-19 01:37 +0000
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:38 -0800
Re: Dictionaries with tuples or tuples of tuples Dave Angel <davea@davea.name> - 2013-02-18 20:51 -0500
Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 20:56 -0500
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:17 -0800
Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 21:54 -0500
Re: Dictionaries with tuples or tuples of tuples Dave Angel <davea@davea.name> - 2013-02-18 22:14 -0500
Re: Dictionaries with tuples or tuples of tuples Mitya Sirenef <msirenef@lightbird.net> - 2013-02-18 22:56 -0500
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:17 -0800
Re: Dictionaries with tuples or tuples of tuples Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-02-19 02:34 +0000
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:39 -0800
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 18:39 -0800
Re: Dictionaries with tuples or tuples of tuples Jon Reyes <everystepsayes@gmail.com> - 2013-02-18 17:38 -0800
csiph-web