I think that the issue is solved easier than I made it up, but my head is already bent and can not find other choice. I hope you will tell such.
There is an array of data represented as plain text. In this array are the values from multiple entities. These entities are grouped in a separate list. The values for each entity are blocks separated by an empty line. The example below in the code. The number of values for each entity may vary.
dataset_names = ["moscow", "new-york"]
text = """2008 11 186
2009 11 281
2011 11 776
2012 11 856
2011 11 776
2012 11 856"""
def chunks(l, n=2):
"""Splits the list (l) into parts of size n"""
for i in range(0, len(l), n):
yield l[i:i + n]
prepare_text = text.replace(' ',").replace('\n','\t').split('\t\t')
data = [list(chunks(item.split('\t'))) for item in prepare_text]
What I do now: remove the spaces (they are not perceived at the destination), divided into blocks, divide blocks in pairs.
And then, as already wrote, the brain falls into a cycle and come eventually to the same solution which does not give the desired result. Shouldn't be that hard to compare both lists and add in chunks the names of datasets, but then to pull out the data in the proper formatting?
Ultimately I want to get something like this:
value_1 = 2008
value_2 = 11186
value_1 = 2009
value_2 = 11281
Simply put, I want to bring to each entity from one list all the corresponding values from the other, further breaking them by pairs.
Please, send in the right direction.