挑战Python100题(10)
•
Python
100+ Python challenging programming exercises 10

Question 91
By using list comprehension, please write a program to print the list after removing the 0th,4th,5th numbers in [12,24,35,70,88,120,155].
Hints: Use list comprehension to delete a bunch of element from a list. Use enumerate() to get (index, value) tuple.
通过列表理解,请编写一个程序,在删除[12,24,35,70,88120155]中的第0、4、5个数字后打印列表。
提示:使用列表理解从列表中删除一堆元素。使用enumerate()获取(index,value)元组。
Solution:
li = [12,24,35,70,88,120,155] li = [x for (i,x) in enumerate(li) if i not in (0,4,5)] print(li)
Question 92
By using list comprehension, please write a program to print the list after removing the value 24
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/c6ed58bba2.html
