Can someone help me with this super newbie python problem. I tried googling multiple times.
This is the list I have been provided:
fruits = [{"key":"Red","value":"Apple"},
{"key":"Yellow-0","value":"Mango"},
{"key":"Green","value":"Banana"}]
In some cases it could also be just:
fruits = [{"key":"Yellow-0","value":"Mango"}]
Problem Statement
I want to iterate over this list and match only when there's a Yellow-0 or Yellow-1 and so on until Yellow-9
My code
import re
fruits = [{"key":"Red","value":"Apple"},
{"key":"Yellow-0","value":"Mango"},
{"key":"Green","value":"Banana"}]
keyword = r"Yellow-\d"
for key in fruits:
if keyword:
print(fruits)
My Output:
[{'key': 'Red', 'value': 'Apple'}, {'key': 'Yellow-0', 'value': 'Mango'}, {'key': 'Green', 'value': 'Banana'}]
[{'key': 'Red', 'value': 'Apple'}, {'key': 'Yellow-0', 'value': 'Mango'}, {'key': 'Green', 'value': 'Banana'}]
[{'key': 'Red', 'value': 'Apple'}, {'key': 'Yellow-0', 'value': 'Mango'}, {'key': 'Green', 'value': 'Banana'}]
My Desired Output is to match Yellow-0 and return true as this will be part of a function
Yellow-0