# Code Not Working Properly – Trying To Create A Simple Graph

I’m way too lazy to type in all that data everytime I run your script, so I automated that part to make development and testing of it easier. Likewise, I think the easiest thing to do would be to use the `collections` module’s `defaultdict` class to keep track of what dates have been seen and the total number of cases seen on each of them. Here’s what I mean:

``````from collections import defaultdict

#CoronaCaseNumber = input("")
#CoronaList = CoronaCaseNumber.split(" ")
#LuckyNumber = CoronaList[0]
#Date = CoronaList[1]
#Date2 = CoronaList[2]
LuckyNumber, Date, Date2 = "8 20200401 20200404".split(" ")

data = """\
HP4 20200402 1
HP5 20200402 1
HP1 20200401 1
HP2 20200401 1
HP3 20200401 1
HP6 20200403 0
HP6 20200404 1
HP7 20200404 1
""".splitlines()

LuckyNumero = int(LuckyNumber)
DateList = []
CaseNumberList = []
for case in range(LuckyNumero):
CoronaCaseData = data[case]
CoronaList2 = CoronaCaseData.split(" ")
InfoDate = CoronaList2[1]
DateList.append(InfoDate)
CaseNumber = CoronaList2[2]
CaseNumberList.append(CaseNumber)

DailyCases = defaultdict(int)

for i, d in enumerate(DateList):
if Date <= d <= Date2:  # Valid date?
DailyCases[d] += int(CaseNumberList[i])

# Print daily cases sorted by date (i.e. the dictionary's keys).
for date in sorted(DailyCases, key=lambda d: int(d)):
print("{}:{}".format(date, '*' * DailyCases[date]))
``````

Output:

``````20200401:***
20200402:**
20200403:
20200404:**
``````