Just like the title but how do I check if a certain element is an integer and square those in list while deleting elements that aren't integer?
For example, the list is [0, 2, 'Python', 'C++', 3]
And this is what I tried:
def main():
lst = [0, 2, 'Python', 'C++', 3]
print("Given list: ", lst)
newLst = [item**2 for item in lst if type(lst[item]) == int]
print("The list which only contains square of integers: ", newLst)
main()
And error happens;
TypeError: list indices must be integers or slices, not str
What am I missing?