python blind practice

  • Demand: irregular listing singlelist3 = [ 'total', 'per ton of artificial:', 'total man', 1748.07, 'amount'], if the current position of the next adjacent element and the element is a string of characters remains string, then insert 0 after the number of the element, as singlelist3 = [ 'total', 0.00 'artificial ton:', 0.00 'total man', 1748.07, 'amount', 0.00]
def expandstr(mylist):
if isinstance(mylist[-1],str):
mylist.append(0.00)
indexlist = []
i=0
while i<len(mylist)-1:
myval = mylist[i]
if isinstance(mylist[i+1], str) and isinstance(myval, str):
indexlist.append(i)
else:
print("hi")
i+=1
indexlist=list(map(lambda x:x+1,indexlist))
mylist.insert(indexlist[0],0.00)
i=1
while i<len(indexlist):
mylist.insert(indexlist[i]+1,0.00)
i+=1
print("expand: ",indexlist)
print("expand: ",mylist)

 

Guess you like

Origin www.cnblogs.com/saintdingspage/p/11372405.html