Sto Ned
Sto Ned

Reputation: 9

Extract a letter from a list of numbers

I have this problem:

number = 'a1234'
alphabet= ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

I need to convert the number to:

number = 1234

But I haven't every time got 'a' in number, I could have any random letter in alphabet array

Can I check this in a faster way than this, if it is possible?

alphabet = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
    for a in pid :
        if a in alphabet:
            pid = pid.replace(a, '')
            pass

Upvotes: 0

Views: 56

Answers (1)

OysterShucker
OysterShucker

Reputation: 5531

You could use a regular expression.

import pdb, re

pdb.set_trace()

pid = 'a1234'
pid = re.sub('[a-zA-Z]', '', pid) #remove all letters from pid
print(pid) #1234

Upvotes: 2

Related Questions