如何更改字符串" Point"成为变量输入(字符串)?
result = []
list = [[a,b,c,d][a,b,c,d]]
result.append( [["Point {}".format(i) for i in range(1, len(sub)+1)] for sub in list])
我基本上不想使用字符串" Point"作为常数而不是另一个参数值。我试过这个:
result = []
list = [[a,b,c,d][a,b,c,d]]
p_name = "Number"
result.append( [[p_name, {}.format(i) for i in range(1, len(sub)+1)] for sub in list])
我想最终:
result = [[Number 1, Number 2, Number 3, Number 4][Number 1, Number 2, Number 3, Number 4]]
谢谢,
答案 0 :(得分:1)
result.append( [["{} {}".format(p_name, i) for i in range(1, len(sub)+1)] for sub in list])