HELP: compile error, cannot import python package re for regex


  • 0
    Y

    this does not compile:

    def isAlphanumeric(self, a):
        import re
        return re.match(r'^[a-zA-Z0-9]$', a) != None
    

    yet this does:

    def isAlphanumeric(self, a):
        return len(a) == 1 and a in 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
    

    seem we cannot import regex package, is it general that we cannot export any library?


  • 1
    E

    Try remove the line of import, it seems that the collections are automatically imported.
    It worked for me!
    -K


  • 0
    G

    Agree. Same thing on string.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.