我有这个清单,
['1A11','1A12','1A13','1A14','1A15','1A16','1A17','1A18']
如何使用python创建列表,该列表使用上面的范围并将输出打印为:
$scope.keyLength = function (obj) {
return Object.keys(obj).length;
}
感谢。
答案 0 :(得分:1)
def make_range(pre, r):
return ['{0}{1}'.format(pre, i) for i in r]
# Example
print (make_range('1A1', range(1, 8)))
# Will print
>>> ['1A11','1A12','1A13','1A14','1A15','1A16','1A17','1A18']
答案 1 :(得分:0)
简单的列表理解:
l = ['1A11','1A18']
result = [ l[0][:2]+str(i) for i in range(int(l[0][2:]), int(l[1][2:])+1) ]
print(result)
输出:
['1A11', '1A12', '1A13', '1A14', '1A15', '1A16', '1A17', '1A18']