1
classement=Counter(results)
liste = classement.most_common()
print(liste)

Now what I have with the above print is

[(u'a', 5), (u'b', 3), (u'c', 2), (u'd', 2), (u'e', 2), (u'f', 2), (u'g', 2), (u'h', 1), (u'i', 1)]

But I would like something like that, I don't know how to format it

a = 5
b = 3
c = 2
etc...
etc...

Thanks for help!

yash
  • 1,357
  • 2
  • 23
  • 34
Diamonds
  • 117
  • 1
  • 9

3 Answers3

1

Instead of just printing your list you can iterate through it printing each key and its value like this:

for key, val in liste:
    print(key, '=', val)
L. MacKenzie
  • 493
  • 4
  • 14
1

With str.format() function:

for k,v in liste:
    print('{} = {}'.format(k,v))
RomanPerekhrest
  • 88,541
  • 4
  • 65
  • 105
0

print(liste) will print the entire list. But you need to iterate through each element in the list. You can do it as

for key,val in liste:
        print('{} = {}'.format(key,val))

Since each element in the liste corresponds to a tuple,the statement key,val in liste will unpack the tuple and you can print them however you want it.

yash
  • 1,357
  • 2
  • 23
  • 34