简体   繁体   English

元组中的Python元组

[英]Python Tuple within a Tuple

I have a python question. 我有一个python问题。

I generated this list 我产生了这个清单

14:00,18.7,383.5,266405,5480,212500,183750,52380,6804,57150,17431,65567
14:01,18.7,383.5,226430,6600,210850,206700,51870,11868,69850,18486,59222

Now I want to make it into 现在我想把它变成

('14:00', 18.7, 383.5,
(266405, 5480, 212500, 183750, 52380, 6804, 57150, 17431, 65567)),

('14:01', 18.7, 383.5,
(226430, 6600, 210850, 206700, 51870, 11868, 69850, 18486, 59222)),

I have learned how to convert a list into a tuple, by doing tuple(list) 我已经学习了如何通过执行tuple(list)将列表转换为元组

But I have no idea how to create a tuple and quote within a tuple.. 但是我不知道如何创建一个元组并在元组中引用。

Can anyone help? 有人可以帮忙吗?

Use slicing to get sub-sequence, and convert it to tuple using tuple . 使用切片得到部分序列,并将其转换为tuple使用tuple

>>> lst = ['14:00',18.7,383.5,266405,5480,212500,183750,52380,6804,57150,17431,65567]
>>> tuple(lst[:3]) + (tuple(lst[3:]),)
('14:00', 18.7, 383.5, (266405, 5480, 212500, 183750, 52380, 6804, 57150, 17431, 65567))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM