Supposed I have a string of randomly generated values,
string = 'ZlgKgIvhPGClfDtmaXjtqQMohOiNZuGaKwSyKsHAcAmpfDXOTUZIfwOvmlotZrquFDFvIvOZ'
and some positions as a list of tuples,
pxn = [(2, 10), (13, 20)]
where the tuples represent the starting and ending positions of the string.
I have been trying to write a function that would return segments of the string according to the positions given, so it'd look something like that
segment = ['lgKgIvhPG','fDtmaXjt']
I have had an attempt at it by doing something like this,
def find_region(string):
" function that returns the string in segments by starting and ending positions provided"
for code, start, end in list:
if index.string == start:
if index.string == end:
return code
which obviously does not work, but I don't really know how to proceed further.
Edit: And supposed string and pxn are keys that exist in a dictionary that looks something like this
{'string':'ZlgKgIvhPGClfDtmaXjtqQMohOiNZuGaKwSyKsHAcAmpfDXOTUZIfwOvmlotZrquFDFvIvOZ', 'pxn': [(2, 10), (13,20)]}
How would one then approach this problem? Any help would be much appreciated. Thank you.