I have a list:
data = ["data 01", "data 02", "data 03"]
I want to check if each element in list contain the string "data", and also add the text after data (e.g 01, 02, 03) to another list. Below is the code I have, but I find it to be inefficient.
data_2 = []
for item in data:
if ("data" in item):
data_2.append(item.replace("data", "").strip())
Is there a way to check
if item == "data {}"
Where {} is a numerical variable. As a precaution to having an item in data list like ["no data"], where the string "no" gets added by mistake?
item.startswith('data')