Welcome to LeetCode Discuss.  Please read the FAQ to help yourself making the best use of Discuss.
Ask a Question
Back to Problem

Welcome to LeetCode Discuss.

This is a place to ask questions related to only OJ problems.

Please read the FAQ to help yourself making the best use of Discuss.

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

0 votes
52 views

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?

asked Feb 24 in Valid Palindrome by yanggao (140 points)

1 Answer

0 votes

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

answered Mar 17 by esquroot (160 points)

...