Oct-06-2020, 01:02 AM
I have a function called display(dict) that takes a dictionary as a parameter and displays all the elements of the dictionary. It should only display 8 elements per line. In this program I read a file filled with teams that won the baseball world series. The key in the dictionary is the name of the team and the value is a set filled with the years each team won. But I can't get my code to print out 8 values per line. Can you please look at my code and give me some tips?
def display(winning_dict): count = 1 for key, value in winning_dict.items(): print(key, ':') print(value) count += 1 if count == 8: print(value)This is an example of what my code display:
Output:New York Yankees :
{1923, 1927, 1928, 1932, 1936, 1937, 1938, 1939, 1941, 1943, 1947, 1949, 1950, 1951, 1952, 1953, 1956, 1958, 1961, 1962, 1977, 1978, 1996, 1998, 1999, 2000}
Washington Senators :
{1924}
none :
{1904, 1994}
You will notice in my output that it display the years no team won the world series. I am not supposed to display this part of the dictionary but I am not allowed to just delete it. How can I avoid printing this part out?