[Tutor] how to delete some quasi-duplicated keys

Andreas Perstinger andreas.perstinger at gmx.net
Sun Nov 27 12:03:51 CET 2011


On 2011-11-26 03:49, lina wrote:
>
>          for k, v in occurence.items():
>              print(v,k)
>
> 292 frozenset({66, 69})
> 222 frozenset({24, 27})
>
>
> How can I let the result like:
>
> 292 {66,69}
> 222 {24,27}
>
> don't output the frozenset

If you want to use your own output format you have to provide it.

For example, you could use a combination of string formatting and 
".join()" to get what you want:

for k, v in occurence.items():
     print("{0} {{{1}}}".format(v, ",".join([str(x) for x in k])))

Bye, Andreas


More information about the Tutor mailing list