Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #26815
| Date | 2012-08-09 17:23 -0400 |
|---|---|
| From | Dave Angel <d@davea.name> |
| Subject | Re: no data exclution and unique combination. |
| References | <864b0104-daa8-4ea5-8003-6cfaab19fdea@googlegroups.com> <bccc20ed-7570-4e15-980c-008987ce0361@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3119.1344547435.4697.python-list@python.org> (permalink) |
On 08/09/2012 04:06 PM, giuseppe.amatulli@gmail.com wrote:
> <SNIP>
>
> print unique
> {(4, 5): 1, (5, 4): 1, (4, 4): 2, (2, 3): 1, (4, 3): 2}
>
> I choose this solution because i could not install "from collections import Counter".
Nothing to install, at least for Python 2.7. collections is in the
standard library, and Counter is in collections (new in version 2.7)
> Anyway how i can print to a file the unique results without the brackets and obtain something like this?
> 4 5 1
> 5 4 1
> 4 4 2
> 2 3 1
> 4 3 2
>
>
To print out a dict in an explicit format, you want a loop.
for key, val in unique.items():
print key[0], key[1], val
Note that you cannot guarantee the order they will print out, once
stored in a dict. You may want to sort them, or otherwise order them if
it matters.
<SNIP>
Note I added my responses after the parts of your message that I was
quoting. To put the response first is called top-posting, and against
policy here.
--
DaveA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
no data exclution and unique combination. giuseppe.amatulli@gmail.com - 2012-07-24 11:27 -0700
Re: no data exclution and unique combination. MRAB <python@mrabarnett.plus.com> - 2012-07-24 19:51 +0100
Re: no data exclution and unique combination. MRAB <python@mrabarnett.plus.com> - 2012-07-24 20:08 +0100
Re: no data exclution and unique combination. Terry Reedy <tjreedy@udel.edu> - 2012-07-24 15:32 -0400
Re: no data exclution and unique combination. giuseppe.amatulli@gmail.com - 2012-08-09 13:06 -0700
Re: no data exclution and unique combination. Dave Angel <d@davea.name> - 2012-08-09 17:23 -0400
Re: no data exclution and unique combination. Terry Reedy <tjreedy@udel.edu> - 2012-08-09 17:33 -0400
Re: no data exclution and unique combination. Hans Mulder <hansmu@xs4all.nl> - 2012-08-10 10:47 +0200
csiph-web