Value added to the list, does not change the original ordering

Title: It exists a STR [] a list, which contains already arranged sequence to achieve without changing the input digital automatic sorting original order.

1. inserted in order to achieve values:

list = [1,3,6,8,9,18,] # define a list 
DEF Zhengxu (Numb):
for X in Range (len (List)):
IF List [X]> Numb:
IND = X
List .insert (IND, Numb)
Print (list)
BREAK
elif X == len (list) -1: # than when the elements of the input element of the list of any large when the last digital printing
list.append (Numb)
Print ( List)
Zhengxu (. 5)
Print results:

 

2. Insert achieved descending values:

list1 = [19,17,10,9,8,5] # define a list 
DEF daoxu (numb1):
for Y in Range (len (List1)):
IF List1 [Y] <numb1:
IND1 = Y
List1. INSERT (IND1, numb1)
Print (List1)
BREAK
elif len (List1) -1 == Y: # than when the input element of a list of any small element when the last digital printing
list1.append (numb1)
Print (List1 )
daoxu (2)

printed results:

 

 

Balls to refuel ah

 by: meatball

Guess you like

Origin www.cnblogs.com/shumei/p/12077089.html