[英]List formatting in python
I have a list that looks like this (but a lot larger):我有一个看起来像这样的列表(但要大得多):
list = [0.010128, 0.007897, 0.999918, 8890, 1.97, 424, POLARIS;, UMI, ALPHA], ['0.462045', '0.181562', '0.868072', '8538', '2.66', '403', 'RUCHBAH;', 'CAS', 'DELTA']
I want to format the list to change/combine the last 3 items:我想格式化列表以更改/组合最后 3 个项目:
list = [0.010128, 0.007897, 0.999918, 8890, 1.97, 424, 'POLARIS', 'UMI ALPHA'], ['0.462045', '0.181562', '0.868072', '8538', '2.66', '403','RUCHBAH', 'CAS 'DELTA']
but I just can't seem to get it done.但我似乎无法完成它。
You can combine last 3 items in list using following code:您可以使用以下代码组合列表中的最后 3 项:
list = [0.010128, 0.007897, 0.999918, 8890, 1.97, 424,'POLARIS', 'UMI', 'ALPHA']
x1=list[0:6]
data=list[6:9]
print data
x=" ".join(data)
print x
x1.append(x)
print x1
output:输出:
[0.010128, 0.007897, 0.999918, 8890, 1.97, 424, 'POLARIS UMI ALPHA']
If you want to combine last two items then use如果你想结合最后两个项目然后使用
x1=list[0:7]
data=list[7:9]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.