- 帖子
- 14
- 精华
- 0
- 积分
- 49
- 阅读权限
- 10
- 注册时间
- 2017-10-4
- 最后登录
- 2017-10-18
|
def sanitize(time_string): #这个函数是吧list当中的“-”、“:”、都换成“."
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return(time_string)
(mins,secs) = time_string.split(splitter)
return(mins + '.' + secs)
apple0 =[]
apple = ['2-23', '2.11', '2.59', '2:11', '2:23', '3-10', '3-21', '3.21', '3:10']
for each in apple:
apple0.append(sanitize(each)) #求详细解释一下这句话,
#能否换成几个等式一步步的解释
#我尝试着换了一下,只想到了一个
#除了下面的更换方法,还有再分解细致的
apple1 = sorted(apple0)
print(apple1)
orange0 =[]
orange = ['2-23', '2.11', '2.59', '2:11', '2:23', '3-10', '3-21', '3.21', '3:10'] #和apple0一样
for each1 in orange:
each2 = sanitize(each1)
orange0.append(each2) #只需要将each2放入orange0中即可,
#不一定放在最后,有无其他方法(内置的函数)
orange1 = sorted(orange0)
print(orange1)
最终的结果是apple1=orange1为True
|
|