var = ('3', [11, 13, 11, 11]) I want to convert it into something like this:
3 11 13 11 11 so that I can pass it into another function
foo(*args): ... You could use iterable unpacking to do this.
You can unpack an iterable by prefixing it with * when passing it into a function.
foo(int(var[0]), *var[1]) would give you what you want.
i would suggest using a for loop to check if any item is an instance of list,tuple,dict,this is the code for the procedure:
var = ('3', [11, 13, 11, 11]) types=(list,dict,tuple) var=list(var) num=0 for x in var: item=var[num] num+=1 if isinstance(item,types): item2=item for x in item: var.append(x) continue var.remove(item2) continue here is an explanation of each line of code:
in types you store each possible type of container which could be found, this will be used when checking if the item is an instance of these classes. Next the variable is converted into a list as tuples are not mutable. num is the index(computers start counting from 0). The for loop just loops through each item and then the if block checks if the item is or is not an instance of the classes mentioned earlier in types variable.
foo(var[0], *var[1])…var[0]toint, though.