no data exclution and unique combination.

Dave Angel d at davea.name
Thu Aug 9 17:23:30 EDT 2012


On 08/09/2012 04:06 PM, giuseppe.amatulli at 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




More information about the Python-list mailing list