2
如果一个有编号的一个长长的清单:像查找(开始:结束)列表中的子列表。 Python的
sub_lists=[['130','90','150'],['90','150'],['120','160','45','67']]
example=['130','90','150','123','133','120','160','45','67','55','34']
和子列表列表中你会如何生成一个函数,这些子列表,让您的位置,他们发生在原始字符串中? 得到的结果:
results=[[0-2],[1-2],[5-8]]
我试图沿
example=['130','90','150','123','133','120','160','45','67','55','34']
sub_lists=[['130','90','150'],['90','150'],['120','160','45','67']]
for p in range(len(example)):
for lists in sub_lists:
if lists in example:
print p
线的东西,但是,这不是工作?
我采取'结果= [0-2],[1-2],[5-8]'只是你自己的符号来说明什么ñ如果你真的想把它作为一个字符串来获取,你应该使用字符串替换。像'return'result = [[%d-%d],[%d-%d ...“%(<数值序列>))。 – mac
[Python:查找列表中子列表的起始和结束索引]的可能重复(http://stackoverflow.com/questions/17870544/python-find-starting-and-ending-indices-of-sublist-in-list) –