moderator: don't use update
to add a new entry. Instead use =
as per the slides. See post on update vs = below for more details.
I got stuck on this challenge.
The solution is:
performances = {}
schedule_file = open('schedule.txt', 'r')
for line in schedule_file:
(show, time) = line.split(' - ')
performances[show] = time.strip()
print(show, time)
schedule_file.close()
print(performances)
The line that is confusing me is performances[show] = time.strip()
. That's the first that we've seen that syntax, I believe.
Here is what I tried, following along with the video and slides:
performances = {}
schedule_file = open('schedule.txt', 'r')
for line in schedule_file:
(show, time) = line.split(' - ')
performances.append(show, time)
print(show, time)
schedule_file.close()
print(performances)
This seemed to accord with the slides and uses the append method. Perhaps it doesn't work because I'm adding to a dictionary rather than a list, as the example does?