python parsing algorithm and common interview questions

Bubbling 

DEF BubbleSort (the nums):
for I in Range (len (the nums) -1):
Print (I)
for J in Range (len (the nums) -1-I):
Print (J)
IF the nums [J]> the nums [J +. 1]:
the nums [J], the nums [J +. 1] = the nums [J +. 1], the nums [J]
return the nums

the nums = [1,5,2,3]

Print (BubbleSort (the nums))

1.i cycle is sure that the total number of cycles
2.j cycle time is confirmed during cycle i, each time the index number of comparative example, the first cycle i, for j in range (0,3) . 0 : 11: 22: 3 Comparative three









-------------------------------------

string sections

# String sections, taken in a ABCD 
a = "apbocidu"
1.
b=a[::2]

print(b)

a = "apbocidu"

2.
a = "apbocidu"

c=[]
for i in range(len(a)):
if i % 2 ==0:
c.append(a[i])

print(''.join(c))


Method II 1. a cycle corresponding to the index, taking the even-numbered subscripts, then c.append. He added corresponding to the target value
and then to join a string list

Cutting strings
# Cutting string, "hello_world_hehe" converted "Hello", "World", "Hehe" 
A = "hello_world_hehe"

Print (a.split ( "_"))


# Combined string, [ "a", "b ", "c", "d"] combined into "ABCD" 
A = [ 'A', 'B', 'C', 'D'] 
B = "" .join (a) # join the connection string 
print (b)

List of Formula
a=[x*x for x in range(5)]

print(a)


Fibonacci number (recursive)

a=0
b=1
l=[]
while b <100:
l.append(b)
a,b=b,a+b
print(l)


Guess you like

Origin www.cnblogs.com/zhouzhipen/p/11892071.html