I got one problem with sorting and output. I have no idea how should I do that.
The main idea of the program:
- Input total amount of passengers.
- Input total amount of cells.
- Input passengers's data n-times (based on the first input) - ex.: Qwe 11:25 12:34.
- Output sorted data. Output should be like this: name of the passenger, cell number.
n = int(input())
k = int(input())
data = []
for x in range(1,n+1):
data.append(input().replace(":"," ").split(" "))
for elem in data:
elem.append(int(elem[1])*60+int(elem[2]))
elem.append(int(elem[3])*60+int(elem[4]))
while len(elem)>3:
elem.pop(1)
if elem[1]>elem[2]:
raise SystemExit("time of issuing can not be lower than time putting")
Example input of the program:
4
2
Qwe 12:45 16:30
Wer 13:55 17:50
Ert 6:25 12:55
Rew 22:55 23:30
Output:
Ert 1
Qwe 2
Wer 2
Rew 1
"Wer" also can be skipped, because of cells limit (it's a beginning exercise, so it doesn't really mean you need such a good code that will cover everything). I can try to explain how cells work, but I think it's pretty clear from the example output - it's based on time of issuing and time putting comparation.
I'm trying to learn Python, and will be grateful if anyone will answer what should I probably do to complete my script, or rather use another idea for it.
Upd: I got something like this:
data = sorted(data, key=lambda elem: elem[1])
for elem in data: #Just visual check
print(elem)
for x in data:
if j<=k:
if data[i][2]>data[i+1][1]:
print(data[i][0], j+1)
j+=1
i+=1
else:
j=0
print(data[i][0], j+1)
else:
j=0
But it's still not quite what I want. Any ideas?