I want to input two lists and compare each list at the end and print out only the common item '0', what should I do? For example, when you enter it in the shell window,
Enter cammate 1's Monday timetable.
1 hour: 0
2 hours: X
3 hour zone: X
4 hour zone: 0
Enter cammate 2's Monday timetable.
1 hour: 0
2 hours: X
3 hour zone: 0
4 hour zone: 0
Results at the end
Month: [1 hr: 0, 4 hr: 0]
How do we get a common time zone for zero in this way?I don't know how to be a beginner.
timetable1 = {}
day = ["Month"]
For i in day : #i The days of the week in day are repeated from Monday to Friday.
print("Please enter the %s day schedule for Cammate 1 "%i)
day_timetable1 = [ ] #List to receive the day's timetable
For jin range(1,8): #Enter from 1st period to 7th (8-1) period
day_timetable1.append(input("%d time zone:"%j)) #Received by each class
Time table1[i] = day_time table1 #timetable["day"].
timetable2 = {}
for i in day :
print("Please enter the %s day schedule for Cammate 2 "%i)
day_timetable2 = [ ]
for j in range(1,8):
day_timetable2.append(input("%d time zone:"%j))
timetable2[i] = day_timetable2
What should I add to get the common items...?
python list
Day = 'Mon'
for j in range(7):
Matches = []
if table1[day][j] == timetable2[day][j] == '0':
Something that matches.append("%d time zone:0"%(j+1)
print("%s: [%s]"%(day, ", ".join(matching)))")
© 2025 OneMinuteCode. All rights reserved.