-2

number_of_fails(['1','2','3']) # this is my current array, I want it to be int

coverted_nof = int(number_of_fails) # what I tried to do to convert to an int

output:

TypeError: only size-1 arrays can be converted to Python scalars

Rugby15
  • 1
  • 1

1 Answers1

0

initializing list

array = ['a1', '2', '3', '4', '5'] 

for i in range(0, len(array)): 
    if array[i].isdigit():
        array[i] = float(array[i])

Printing modified list

print ("Modified list is : " + str(array)) 

Modified list is : ['a1', 2.0, 3.0, 4.0, 5.0]

David Dias
  • 13
  • 3