TypeError: unhashable type: 'list'

Peter Otten __peter__ at web.de
Wed Oct 23 04:11:56 EDT 2019


joseph pareti wrote:

> I am experimnenting with this (reproducer) code:
> pattern_eur    = ['Total amount']

Make that 

pattern_eur = 'Total amount'

>    match_C = re.search(pattern_eur, element)

The first argument to re.search() should be a string, not a list of strings:

>>> import re
>>> re.search("foo", "bar")
>>> re.search(["foo"], "bar")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/re.py", line 170, in search
    return _compile(pattern, flags).search(string)
  File "/usr/lib/python3.4/re.py", line 282, in _compile
    p, loc = _cache[type(pattern), pattern, flags]
TypeError: unhashable type: 'list'


>     element = element + 2

This will be your next problem; you are adding 2 to a string.




More information about the Python-list mailing list