如果我理解得很好,您希望看到所有以给定数字开头的条目......但重新编号?
# The original list
>>> a = ['1 is the population', '1 isnt the population', '2 is the population']
# split each string at the first space in anew list
>>> s = [s.split(' ',1) for s in a]
>>> s
[['1', 'is the population'], ['1', 'isnt the population'], ['2', 'is the population']]
# keep only whose num items == '1'
>>> r = [tail for num, tail in s if num == '1']
>>> r
['is the population', 'isnt the population']
# display with renumbering starting at 1
>>> for n,s in enumerate(r,1):
... print(n,s)
...
1 is the population
2 isnt the population
如果您(或您的老师?)喜欢这里的一个班轮是一条捷径:
>>> lst = enumerate((tail for num, tail in (s.split(' ',1) for s in a) if num == '1'),1)
>>> for n,s in lst:
... print(n,s)
...
1 is the population
2 isnt the population