Jul-25-2019, 03:26 PM
How to print counter without bracket and sort result in python ?
I need to have this final result :
But I'v got this :
Here is my code :
Or this result but not sorted with this print options :
Thanks for any help.
I need to have this final result :
1 2 3 4 5 |
2 : 2 3 : 3 4 : 4 5 : 3 7 : 2 |
1 |
Counter({ 4 : 4 , 3 : 3 , 5 : 3 , 2 : 2 , 7 : 2 }) |
1 2 3 4 5 6 7 8 9 10 11 |
counter = collections.Counter(lst) print (counter) counter.keys() for key, value in counter.items(): #print(key,":", value) ctx = (key, value) print (ctx) tab.append(ctx) tab.sort() #print(tab) #print(*tab, sep = "\n") |
1 |
print (key, ":" , value) |
1 2 3 4 5 |
3 : 3 4 : 4 2 : 2 5 : 3 7 : 2 |
