Home > Back-end >  how to convert list into tuple in python , all elements of list should be in int?
how to convert list into tuple in python , all elements of list should be in int?

Time:12-30

use proper example for clarification

I need solution through code list tuple w

list should be changed in tuple int first then convert into tuple

CodePudding user response:

_list = [1, 2, 3, "hello", "world"]
_tuple = tuple(_list)

CodePudding user response:

l = ["1", "2", "3", "4"]
l_int = [int(i) for i in l] # Convert everything to int one by one and save in new list to later convert to tuple

t = tuple(l_int) 

Like this?

  • Related