结合范围和数字列表的python

结合范围和数字列表的python

本文介绍了结合范围和数字列表的python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

range(5, 15) [1, 1, 5, 6, 10, 10, 10, 11, 17, 28]
range(6, 24) [4, 10, 10, 10, 15, 16, 18, 20, 24, 30]
range(7, 41) [9, 18, 19, 23, 23, 26, 28, 40, 42, 44]
range(11, 49) [9, 23, 24, 27, 29, 31, 43, 44, 45, 45]
range(38, 50) [1, 40, 41, 42, 44, 48, 49, 49, 49, 50]

我从功能的打印命令中获得上述支出.我真正想要的是范围的组合列表,例如,在顶行5,6,7 ... 15,1、1,5,6等.输出范围来自

I get the above outpout from a print command from a function. What I really want is a combined list of the range, for example in the top line 5,6,7...15,1,1,5,6 etc.The output range comes from

range_draws=range(int(lower),int(upper))

我天真地认为会给出一个范围.其他数字来自切片列表.

which I naively thought would give a range. The other numbers come from a sliced list.

有人可以帮助我获得预期的结果吗?

Could someone help me to get the desired result.

推荐答案

range()函数返回特殊的范围对象保存在内存中(只有开始,结束和步长大小时,无需将所有数字保留在内存中).将其投射到列表以扩展"它:

The range() function returns a special range object to save on memory (no need to keep all the numbers in memory when only the start, end and step size will do). Cast it to a list to 'expand' it:

list(yourrange) + otherlist

引用文档:

这篇关于结合范围和数字列表的python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:59