I have a list with a string:
a = ["1, 2, 3, 4"]
I want to get every number within that list, turn them into integers, and return the largest and smallest value in that list. I've already tried doing this with FOR IN
like this:
def high_and_low(numbers):
y = []
for x in numbers:
if(x == " " or ","):
continue
x = int(x)
y.append(x)
numbers = y
mx = max(numbers)
mn = min(numbers)
return [mx, mn]
a = ["1, 2, 3, 4"]
print(hl(a))
But it did not work, and something very strange happened to another list of strings:
def high_and_low(numbers):
y = []
for x in numbers:
x = int(x)
y.append(x)
numbers = y
mx = max(numbers)
mn = min(numbers)
return [mx, mn]
a = ["1", "2", "3", "4"]
print(hl(a))
With this list above, which contains four Strings, it worked and I do not know why.