0
Any better way to typecast variables in my function given below ?
https://code.sololearn.com/c3sxM7IrO2SL/?ref=app def diff(l,n): a=int(l[0]) b=int(l[0]) c=0 for i in range(n): if a>int(l[i]): a=int(l[i]) if b<int(l[i]): b=int(l[i]) c=b-a return c
2 odpowiedzi
+ 2
use list comprehension in the function to converts the elements (currently strings) to a list of integers....then use the max and min functions and subtract them and return it.
(no need to pass the 'n'.)
0
rodwynnejones
Thank you for the help, it does work.
Yes, built in functions are there, but I was just trying to explore through codes. It would be helpful in complex programs though