Python Compare month list to base list and show both

Asked

Viewed 867 times

1

I have a list of months from January to December. I have another list that has the month and a value. For example:

Jan = 12.00

Fev = 15.00

Ago = 10.00

I want to display the whole year and show every month. Months that have no value at all should appear as 0.

  • 2

    Post your code, it’s easier to help you.

  • It’s a list or a dictionary?

  • This list of months I have is a dictionary months = [Jan,Feb...] .. and the other list is the result of a query, if it has the value it displays the month

1 answer

0


I suppose it’s something like that:

meses = ['jan', 'fev', 'mar', 'abr', 'mai', 'jun', 'jul', 
                         'ago', 'set', 'out', 'nov', 'dez']

valores = {'jan' : 12, 'fev' : 15, 'ago' : 10}

for mes in meses:
    if mes in valores:
        v = valores.get(mes)
    else:
        v = 0

    print(mes + " " + str(v))
  • was worth it! Obriagdo Pedro

Browser other questions tagged

You are not signed in. Login or sign up in order to post.