挑战Python100题(10)

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

版权声明:本文为博主作者:Hann Yang原创文章,版权归属原作者,如果侵权,请联系我们删除!

原文链接:https://blog.csdn.net/boysoft2002/article/details/135372120

共计人评分,平均

到目前为止还没有投票!成为第一位评论此文章。

(0)
xiaoxingxing的头像xiaoxingxing管理团队
上一篇 2024年1月16日
下一篇 2024年1月16日

相关推荐