1

I have a function like this.I need to print two dictionaries side by side in python.

def kelime_sayma(metin):
    kelimeler = metin.split()
    kelime_sayi = Counter(kelimeler)

    for i,value in kelime_sayi.most_common():
        print('{}    {}'.format(i, value))
    for j,value in sorted(kelime_sayi.items()):
        print('{}    {}'.format(j, value))
Ch3steR
  • 20,090
  • 4
  • 28
  • 58
mcora
  • 43
  • 5

2 Answers2

1

You can try :

>>> a
['c', 'a', 'b', 'b', 'c', 'b', 'b', 'b', 'a', 'a', 'b', 'a', 'b', 'c', 'c', 'a', 'c', 'a', 'a', 'b', 'a', 'a', 'c', 'a', 'b', 'c', 'c', 'c', 'b', 'a']
>>> b=Counter(a)
>>> b
Counter({'a': 11, 'b': 10, 'c': 9})
>>> for i,j in zip(b.most_common(), b.items()):
...     print('{} {} {} {}'.format(i[0], i[1], j[0], j[1]))

Output:

a 11 c 9
b 10 a 11
c 9 b 10
abhilb
  • 5,639
  • 2
  • 20
  • 26
1

Question: print two dictionaries side by side

    for i, v1, v2 in enumerate(zip(kelime_sayi.most_common(), sorted(kelime_sayi.items()), 1):
        print('{}    {} {}'.format(i, v1, v2))
stovfl
  • 14,998
  • 7
  • 24
  • 51