user3097526 user3097526 - 5 months ago 17
Python Question

Iterate over a badly formed set with python

I've got a batch of PDF documents with the following metadata property:
Language:

set([NL,DE,FR,EN])


I want to iterate these values but it outputs each char like:

s
e
t
(
[
...
E
N
,
]
)


My guess is that the set is missing quotes.
set(["NL","FR","DE","EN"])


Is there a way so I can still iterate the values? If so, I could rewrite the property.

Answer
for lang in re.findall("[A-Z]{2}",metadata_text):
    print lang

I guess maybe?

alternatively

for lang in metadata_text[5:-2].split(","):
    print lang