Python Regular Expressions problem:
How do you get string data from file of say rows of IP address
and city location values obtained from re.finditer patterns to
appear in the same dictionary?
for example:
text file has
100.200.10.255 New York City
10. 16. 25.254 Los Angeles
segment of code includes
for item in re.finditer(the_two_patterns, text_file,
re.MULTILINE):
print (item.groupdict())
result is below that I am getting
{‘IP’: ‘100.200.10.255’, ‘city’: None}
{‘IP’: None, ‘city’: ‘New York City’}
{‘IP’: ‘10.16.25.254’, ‘city’: None}
{IP’: None, ‘city’: ‘Los Angeles’}
what I am wanting to see in results is IP and its associated
city location appearing both in same dictionary output like this
below
{‘IP’: ‘100.200.10.255’, ‘city’: ‘New York City’}
{‘IP’: ‘10.16.25.254’, ‘city’: ‘Los Angeles’}
any ideas on how to do that? with re.finditer and groupdict()
?