How to convert a list of tuples into a list of numbers with Python

1 Answer

0 votes
import re 
  
lst_tpl = [(4, 2), (3, 6), (7, 1), (9, 8)] 
  
r = re.sub(r'[\[\]\(\), ]', '', str(lst_tpl)) 
  
lst = [int(i) for i in set(r)] 
  
print(lst) 



'''
run:

[1, 4, 3, 2, 8, 6, 9, 7]

'''

 



answered Dec 15, 2019 by avibootz
...