i have a tuple like this
[
(379146591, 'it', 55, 1, 1, 'NON ENTRARE', 'NonEntrate', 55, 1),
(4746004, 'it', 28, 2, 2, 'NON ENTRARE', 'NonEntrate', 26, 2),
(4746004, 'it', 28, 2, 2, 'TheBestTroll Group', 'TheBestTrollGroup', 2, 3)
]
我希望得到这个而不是那个:
[
(379146591, (('it', 55, 1, 1, 'NON ENTRARE', 'NonEntrate', 55, 1)),
(4746004, (('it', 28, 2, 2, 'NON ENTRARE', 'NonEntrate', 26, 2), ('it', 28, 2, 2, 'TheBestTroll Group', 'TheBestTrollGroup', 2, 3)))
]
对于任何元素来说,除了第一个元素外的所有内容都在它的子元组中,如果下一个元素有与第一个元素相同的元素,则将其设置为前一个元组的另一个子元组。
所以我可以这样做:
for i in data:
# getting the first element of the list
for sub_i in i[1]:
# i access all the tuples inside
有没有一些函数可以做到这一点?