0

while running the code, I am getting an error.

import re

pattern="""
(?P<title>.*)
(-\ located\ in\ )
(?P<city>\w*)
( ,\ )
(P?<state>\w*)"""

for item in re.finditer(pattern,wiki, re.VERBOSE):
    print(item.groupdict())
Utpal Kumar
  • 300
  • 2
  • 13
  • You need to decode `wiki` to string: `wiki.decode('utf8')` (or whatever other encoding you are using) – mozway Jun 24 '22 at 04:15
  • convert `wiki` from `bytes` to `string` - or use prefix `b` in pattern to use `bytes` instead of `string` - `pattern = b"""..."""` – furas Jun 24 '22 at 10:33

0 Answers0