Wednesday, 7 August 2013

Removing letters from a list of both numbers and letters

Removing letters from a list of both numbers and letters

In a function I'm trying to write, the user enters a bunch of numbers e.g.
"648392". I turn this string into a list like this: ['6', '4', '8', '3',
'9', '2'].
I wanted to be able to do sums with these numbers so I was turning the
numbers in the list into integers rather than strings. This all worked
fine, however I also wanted the user to be able to enter letters, and then
I would just remove them from the list - and this is where I'm stuck. For
example a user entering "6483A2".
I can't check to see if an element is a digit with isDigit because the
elements apparently have to be integers first, and I can't convert the
elements in the list to integers because some of the elements are
letters... I'm sure there's a simple solution but I am pretty terrible at
python, so any help would be much appreciated!

No comments:

Post a Comment