当前位置:网站首页>Return to new list

Return to new list

2022-06-24 13:59:00 Beauty of algorithm and programming

Sometimes we need a list to return characters at a specified position , If you use python That solved the problem , It will become very convenient .

problem

Find the element corresponding to the even bit of the incoming list or tuple , And return to a new list .

Method

Use words to describe the idea of solving problems , It can be described with some graphics to better illustrate .

Through the experiment 、 Practice has proved that the proposed method is effective , Is able to solve the problem raised at the beginning .

Code list 1

def f(x):
list1=[]
for I in range(0,len(x),2):
   list1.append(x[i])
print(list1)
x=[1,2,34,5]
f(x)

Conclusion

We can go through python To improve the efficiency of the program .

原网站

版权声明
本文为[Beauty of algorithm and programming]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206241120328787.html