如何为此列表创建步骤?

编程入门 行业动态 更新时间:2024-10-27 15:24:51
本文介绍了如何为此列表创建步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

geom_prog = list(范围(1,n + 1,什么?))

我是如果比率= 2且n = 8,那么该列表将是[1,2,4,8] 所以我不得不放在哪里我把'什么?'一步等于 (列表中的前一个数字)*比率???

解决方案

你需要类似的东西:

geom_prog = [x x in 范围( 1 , 9 ) if (x% 2 == 0 )| (x == 1 )]

虽然在1之后得到所有偶数,但是你需要修改表达式只获得2的幂。

geom_prog = list(range(1, n+1, what?))

I am trying to make is so that if ratio = 2 and n = 8, then the list would be [1,2,4,8] So somehow I have to put where I put 'what?' a step that is equal to the (previous number in the list)*ratio???

解决方案

You need something like:

geom_prog = [x for x in range(1, 9) if (x % 2 == 0) | (x == 1)]

Although that gets all even numbers after 1, so you need to modify the expression to get only powers of 2.

更多推荐

如何为此列表创建步骤?

本文发布于:2023-11-23 09:10:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620889.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:步骤   列表

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!