本文介绍了如何为此列表创建步骤?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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.
更多推荐
如何为此列表创建步骤?
发布评论