I'm solving a problem on codewars, and I needed to create a function that found the smallest number in an array. This is my code:
def find_smallest_int(arr):
smallest_number = arr[0]
for num in arr:
if num < smallest_number:
smallest_number = num
else:
continue
return smallest_number
My answer is correct. But I want to know how I could simplify my code using list comprehension (I'm fairly new to coding). This is what I tried, but I received an error:
def find_smallest_int(arr):
smallest_number = arr[0]
x = [smallest_number for num in arr if num < smallest_number , smallest_number = num]
What would be the correct way to use list comprehension in this case?