python - Issue with sorting and output -


i got 1 problem sorting , output. have no idea how should that.

the main idea of program:

  1. input total amount of passengers.
  2. input total amount of cells.
  3. input passengers's data n-times (based on first input) - ex.: qwe 11:25 12:34.
  4. output sorted data. output should this: name of passenger, cell number.
n = int(input()) k = int(input()) data = []  x in range(1,n+1):     data.append(input().replace(":"," ").split(" "))   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 lower time putting") 

example input of 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" can skipped, because of cells limit (it's beginning exercise, doesn't mean need such code cover everything). can try explain how cells work, think it's pretty clear example output - it's based on time of issuing , time putting comparation.

i'm trying learn python, , grateful if answer should complete script, or rather use idea it.

upd: got this:

data = sorted(data, key=lambda elem: elem[1]) elem in data: #just visual check     print(elem)  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 want. ideas?

you can learn basics of python in 5 minutes sorting howto.

in script, appears parsing times losing passenger info @ elem[0]. need final sort. also, you've appended data 1 list instead of keeping row separate (which necessary sorting).

spending few minutes sorting howto see how organize data make sortable.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

php - HTTP_REFERER woes: How can I allow access to a specific page, only when a visitor has visited another specific page beforehand? -

java Extracting Zip file -