+ 1
List of tuples
This is a program for voting: In the first line, the total number of votes and in the next lines the names of the countries are received as votes Finally, it will print the names of the countries and the number of votes of that country in alphabetical order and in several lines: Input: 5 Italy India India Brazil Spain Output: Brazil 1 India 2 Italy 1 Spain 1 But my output is not like this... What should i do? https://code.sololearn.com/cohymTPyodld/?ref=app
4 Respuestas
+ 9
Amateur ,
this is your code, that is simplified for sorting and output. see also my comments.
https://code.sololearn.com/cB1Vi2z7E6ro/?ref=app
+ 5
Use countries.keys() instead of countries.items()
And then print dictionary according to sorted list values..
+ 5
You can also use comprehension to build a new, sorted dictionary based on the tuples in that sorted list ...
sorted_countries = { e[ 0 ] : e[ 1 ] for e in sorted( countries.items() ) }
print( sorted_countries )
+ 2
Jayakrishna🇮🇳 Ipang Thank u 🌷🌷