4
I have a list with a string:
a = ["1, 2, 3, 4"]
I want to take each number inside that list, turn them into integers, and return the highest and lowest value of that list. I’ve tried this with the FOR IN
in that way:
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 didn’t work, and something very strange happened to another string list:
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 that list up there, which contains four strings, it worked and I don’t know why.