python parse and get more input from line
python
Solution
You can of course, use regex:
import re
str = "my color=red and my color=green"
p = r'color=([a-z]+)'
x = re.findall(p, str)
Problem
I need to parse a text file and get output and add them to list. ``` with open(qwer.txt, 'r') as my_file: a = my_file.readlines() for line in a: for part in line.split(): if "color=" in part: p1 = part.split('=')[1] print(p1) list1 = [] p1.append(list1) ``` so, i have a line where i have two/more "color=" on same line and i need output to get both the colors: my color=red and my color=green my desired output is: ``` red green ``` and i need to add them to a list seperately as ['red','green'] .please help! answers will be appreciated.