Skip to content

Instantly share code, notes, and snippets.

@chuongmep

chuongmep/inserttag.py

Last active Jun 15, 2021
Embed
What would you like to do?
from itertools import groupby, count
bol = [None, "2018",None,None,None,"2018","2019","2020",None,None]
value = "Data"
def get_bol(a):
index = []
for i in range(len(a)-1):
if isinstance(a[i], str):
index.append(i)
return index
def set_bol(a,intervals,value):
for i in intervals:
a[i] = value
return a
def intervals(data):
out = []
counter = count()
for key, group in groupby(data, key = lambda x: x-next(counter)):
block = list(group)
out.append(block[-1]+1)
return out
id = intervals(get_bol(bol))
print(set_bol(bol,id,value))
#Output
# [None, '2018', 'Data', None, None, '2018', '2019', '2020', 'Data', None]
@chuongmep

This comment has been minimized.

Copy link
Owner Author

@chuongmep chuongmep commented Jun 15, 2021

Problem Resolve
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment