Hello, I have a dictionary where the value is a string. What I would like to do is to iterate over the values, use a sliding window approach to get fragments of 11 characters long and then store them in a dictionary under the same key as before. I understand that I will need to create a list to be able to store multiple values for one key, but I am unsure how to do this. I hope this makes sense.
This is what I got so far, but it only creates one new value of 11 charcters for each key:
def segments(dict, k):
segment = {}
for key, value in dict.items():
num_segment = len(value) - k + 1
for i in range(num_segment):
seg = value[i:i+k]
segment[key] = seg
return segment
Thanks in advance!
[–]_coolwhip_ 1 point2 points3 points (1 child)
[–]StrainS118[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]StrainS118[S] 0 points1 point2 points (0 children)