I would approach it this way:
Take away ambiguity: 'number' is integer.
Make a plan. In spoken language: "give me items in list which are not integers".
Find the pieces:
- iterate over elements: use for-loop
- test whether element is integer: use built-in functions isinstance()
- wrap it into list comprehension
Take away ambiguity: 'number' is integer.
Make a plan. In spoken language: "give me items in list which are not integers".
Find the pieces:
- iterate over elements: use for-loop
- test whether element is integer: use built-in functions isinstance()
- wrap it into list comprehension
>>> lst = [1, 'one', 2, 'two'] >>> no_ints = [item for item in lst if not isinstance(item, int)] >>> no_ints ['one', 'two']EDIT: if 'number' is both integers and floats then element testing should be
isinstance(item, (int, float))
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.