Crossin的编程教室
标题:
复杂公式分解
[打印本页]
作者:
incipient
时间:
2017-10-11 15:48
标题:
复杂公式分解
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
作者:
crossin先生
时间:
2017-10-12 11:50
x = sanitize(each)
apple0.append(x)
作者:
incipient
时间:
2017-10-14 10:22
crossin先生 发表于 2017-10-12 11:50
x = sanitize(each)
apple0.append(x)
好的,谢谢。
欢迎光临 Crossin的编程教室 (https://bbs.crossincode.com/)
Powered by Discuz! X2.5