Write a Python program to demonstrate working of Convert String to tuple list
Topic: Write a Python program to demonstrate working of Convert String to tuple list
Solution
test_str = "(1, 3, 4), (5, 6, 4), (1, 3, 6)" print("The original string is : " + test_str) res = [] temp = [] for token in test_str.split(", "): num = int(token.replace("(", "").replace(")", "")) temp.append(num) if ")" in token: res.append(tuple(temp)) temp = [] print(f"List after conversion from string : {res}")
List all Python Programs