I bring you a question that will surely have an obvious solution, but no matter how many times I give it, I can't focus on the problem correctly.
We have a Python dictionary whose length we do not know (and even knowing it, it would not be useful for the case) and precisely because it is a dictionary we cannot take into account the order in which the elements appear.
It would be necessary to reproduce the entire content of the dictionary in a single line, keeping in mind that the code in the 1st line should be the same as in the 5th ( changes in length in the dictionary do not affect the text that is produced ):
fiz = {'Partido Ultra':23792, 'Partido Mega':14959, 'Partido Super':7755, 'Partido Maxi':5054, 'Partido Parguela':4508}
print('Los resultados de las elecciones fueron:{}, {} votos, {}, {} votos, {}, {} votos, {}, {} votos, {}, {} votos, {}, {} votos.'.format(...))
fiz['Partido Über'] = 2176
fiz['Partido Alles'] = 30001
print('Los resultados de las elecciones fueron:{}, {} votos,{}, {} votos,{}, {} votos,{}, {} votos,{}, {} votos,{}, {} votos,{}, {} votos,.'.format(...))
The most obvious solution would be to create a list that in turn serves as a base to form the text string and then extend it for each key-value pair, but I discard it as tremendously inefficient as it increases len(fiz)
. Precisely the interest of the question lies in the way to iterate over several elements when it is not possible or not convenient to define an order .
Would it be necessary to create a function to extend the text indefinitely? Or on the contrary, iterative tools could be used (eg generators, if applicable).
Is this what you are looking for?
Result (one long line):
Note that I have respected your spacing, in which (I don't understand why) you don't put spaces after commas, nor do you separate the number of votes from the word "votes", plus you use the same separator (the comma) to separate between the parties or the parties of their votes, all of which makes the result very unreadable.
In my opinion, this is better: