Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting tuple to list

I am trying to convert this tuple into a list, however when I run this code:

mytuple=('7578',), ('6052',), ('8976',), ('9946',)
List=[]
for i in mytuple:
    Start,Mid,End = map(str, mytuple.split("'"))
    List.append(Mid)
print(List)

I receive this error:

AttributeError: 'tuple' object has no attribute 'split'

The output should be:

[7578, 6052, 8976, 9946]
like image 450
MainStreet Avatar asked Dec 08 '22 13:12

MainStreet


1 Answers

this is what you are looking for

mytuple = (('7578',), ('6052',), ('8976',), ('9946',))
result = [int(x) for x, in mytuple]
print(result)
like image 188
Liam Avatar answered Dec 29 '22 16:12

Liam