python converting/casting result of split of a mixed list to int -
i wonder if there more elegant/pythonic way same result following code:
num1, num2, string = input().split() num1 = int(num1) num2 = int(num2)
where num1 (1 <= num1 <= 15) , num2 (5 <= num2 <= 100) integer , string string consisting of uppercase letters.
you pre-define sequence of respective types , directly cast them using zip (in python 3).
types = (int, int, str) num1, num2, string = (typ(value) typ, value in zip(types, input().split()))
Comments
Post a Comment