I am trying to take input from the user and want to compile regex which consist of each character , I tried using list and using list as an argument which fails.
I dont want to match the complete string but only individual characters to be more specific
x = raw_input("Enter string of length 7 to generate your scrabble helper: ")
a = []
for i in x:
a.append(i)
print(a)
p = re.compile(a)
But this fails !!!!
Traceback (most recent call last):
File "scrabb.py", line 8, in <module>
p = re.compile(a)
File "/usr/lib/python2.7/re.py", line 190, in compile
return _compile(pattern, flags)
File "/usr/lib/python2.7/re.py", line 232, in _compile
p = _cache.get(cachekey)
TypeError: unhashable type: 'list'
I am not sure I understand exacly what you need, but maybe something like this would help:
This should match each character in input string, and not the whole string. You should make sure that there are no special character in user input, but that is other question.