import sys inp = """ 7:00, 7:30, 7:50, 8:30, 9:20, 10:00, 10:30, 11:20, 12:00, 13:40, 14:20, 15:00, 15:30, 16:30, 17:00, 17:40, 18:10, 18:50, 19:20, 20:00, 20:30, 21:10 marsh12,12345,marsh-12-12345-212,212 marsh-12-12345-212,6:00:00,6:00:00,766,1,Иртышская marsh-12-12345-212,,,765,2,Химсбыт marsh-12-12345-212,,,52,3,Парк Победы marsh-12-12345-212,,,50,4,Постышева marsh-12-12345-212,,,49,5,Постышева marsh-12-12345-212,,,47,6,Проспект 100-летия Владивостока marsh-12-12345-212,,,152,7,Молодежная marsh-12-12345-212,,,150,8,Некрасовская marsh-12-12345-212,,,315,9,ВГУЭС marsh-12-12345-212,,,639,10,Студенческая marsh-12-12345-212,,,316,11,Голубиная Падь marsh-12-12345-212,,,317,12,Фуникулер marsh-12-12345-212,,,319,13,Суханова marsh-12-12345-212,,,137,14,"ТЦ ""Изумруд"" " marsh-12-12345-212,,,139,15,Комарова marsh-12-12345-212,,,142,16,Картинная галерея marsh-12-12345-212,,,144,17,Инструментальный завод marsh-12-12345-212,,,146,18,Гоголя marsh-12-12345-212,,,148,19,Гоголя marsh-12-12345-212,,,149,20,Некрасовская marsh-12-12345-212,,,151,21,Молодежная marsh-12-12345-212,,,46,22,Проспект 100-летия Владивостока marsh-12-12345-212,,,48,23,Фирсова marsh-12-12345-212,,,324,24,Магазин marsh-12-12345-212,,,764,25,Химсбыт marsh-12-12345-212,06:40:00,06:40:00,766,26,Иртышская """.split('\n') def timediff(t1, t2): t2 = int(t2.split(':')[0])*60 + int(t2.split(':')[1]) t1 = int(t1.split(':')[0])*60 + int(t1.split(':')[1]) return t2 - t1 def addtime(t, mins): t = int(t.split(':')[0])*60 + int(t.split(':')[1]) + mins return '%02d:%02d:00' % (t/60, t%60) times = inp[0] times = [a.strip()+':00' for a in times.split(',')] trip_line = inp[1].strip().split(',') trip_line[2] += '-%d' trip_id = trip_line[2] trip_line = ','.join(trip_line) stoptimes = [] for line in inp[2:]: stoptimes.append(line.strip().split(',')) duration = timediff(stoptimes[0][1], stoptimes[-1][1]) for i in range(len(times)): print trip_line % i for i in range(len(times)): stoptimes[0][1] = stoptimes[0][2] = times[i] stoptimes[-1][1] = stoptimes[-1][2] = addtime(times[i], duration) print '\n'.join([','.join([trip_id % i,] + a[1:]) for a in stoptimes])
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question