Hi All,
I want to verify if the list objects are integers are not. My code is failing at 0 index, when there is a float value or when there is a string value.
Please help.
I want to verify if the list objects are integers are not. My code is failing at 0 index, when there is a float value or when there is a string value.
Please help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
num = 0 z = [ '11, 12, 14' , '20' , '21, 23' , '24' , 'man' , '1' , '27' , '28' , '29.1' , '30' ] mydefectlist = [] mydefectlist1 = [] mydefectlist2 = [] while num < len (z): z[num] = int (z[num]) num + = 1 for s in z: if ( isinstance (s, int )): flag = 0 mydefectlist.append(s) print ( 'int values:' ,mydefectlist) elif ( isinstance (s, float )): mydefectlist1.append(s) print ( 'float values:' ,mydefectlist1) elif ( isinstance (s, str )): mydefectlist2.append(s) print ( 'string values:' ,mydefectlist2) else : print ( 'please check the list again' , s) |