sis = file("file.sis", "r")
val = file("file.val", "wt")

n = int(sis.readline().strip())

la = sis.readline().strip()


alist = []
for i in xrange(n):
  line = sis.readline().strip()
  alist.append(line.split())
    

for i in xrange(n):
  print map(int, alist[i][0].split(":")), map(int, alist[i][1].split(":"))

In:

07:34 08:55 10 20
08:25 09:00 10 20

Out:

08:25 09:00 10 20
07:34 08:55 10 20
TrustyTony commented: Unclear request +0

Recommended Answers

All 7 Replies

Please explain what you are trying to do. Thanks.

I wish sort "times" in order of size.

17:35
14:24
18:44

Sorted:

14:24
17:35

Pointless forum.

In:
07:34 08:55 10 20
08:25 09:00 10 20
Out:
08:25 09:00 10 20
07:34 08:55 10 20

For a reverse order sort like this, you simply compare for greater instead of lesser, which Python sorts will do with the reverse=True parameter set. Do you also want to take into account the "10 20" which I assume is a date?

For a reverse order sort like this, you simply compare for greater instead of lesser, which Python sorts will do with the reverse=True parameter set. Do you also want to take into account the "10 20" which I assume is a date?

sis = file("file.in", "r")
val = file("file.out", "wt")

n = int(sis.readline().strip())

lao_andmed = sis.readline().strip().split()

def lahaeg(tund, minut, kulunud):
  if minut == 0:
    tund = tund - 1
    minut = 60 - kulunud
  return tund, minut

#print "Ladu: ", lao_andmed

alist = []
for i in xrange(n):
  line = sis.readline().strip()
  alist.append(line.split())
 
temp = [] 
for j in xrange(n): 
  new = alist[j][0].split(":"), alist[j][1].split(":")    
  temp.append(new)

temp = sorted(temp, reverse = True)

print temp

Seems work, but it's ugly code?

"""
06:00 23:00 20 10
07:00 08:00 10 20
08:00 09:00 10 20
"""

10, 20 etc are not important now.

Do you want sorting by duration between times?

And try not to use keywords as a variable name.

on line 23. the new keyword. ;)

Sorry richie, but new is not keyword.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.