I have this piece of code:
a = "aa"
b = 1
c = { "b":2 }
d = [3,"c"]
e = (4,5)
letters = [a, b, c, d, e]
And I want to do something with it, which will empty them. Without losing their type.
Something like this:
>>EmptyVars(letters)
['',0,{},[],()]
Any hint?
Do this:
def EmptyVar(lst):
return [type(i)() for i in lst]
type()
produces the type object for each value, which when called produces an 'empty' new value.
Demo:
>>> a = "aa"
>>> b = 1
>>> c = { "b":2 }
>>> d = [3,"c"]
>>> e = (4,5)
>>> letters = [a, b, c, d, e]
>>> def EmptyVar(lst):
... return [type(i)() for i in lst]
...
>>> EmptyVar(letters)
['', 0, {}, [], ()]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With