Jan-17-2020, 07:54 AM
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.
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)