I'm trying to return specific items in a list based on a pattern.
If the the value '04' appears and the value immediately after it is '01', then return the next 3 values after, but not '04' or '01'. If '04' appears and '01' is not after, then it can be ignored entirely
list = ['04','01','dd','dd','8a','04','2e', '04','01','dd','dd','8a']
for i in list:
if '04' in list and list.index('04')+1 == '01':
new_list = list.index('04')+2
print (new_list)
I tried following the likes of Finding the index of an item in a list, but I couldn't adapt it to my problem.
EDIT:
The list is far longer (3000+ elements), and I need to return the next 172 elements after '04' and '01', not 3. Shouldn't have used that as an example. Apologies!