I have a list of url's and headers from a newspaper site in my country. As a general example:
x = ['URL1','news1','news2','news3','URL2','news1','news2','URL3','news1']
Each URL element has a corresponding sequence of 'news' elements, which can differ in length. In the example above, URL1 has 3 corresponding news and URL3 has only one.
Sometimes a URL has no corresponding "news" element:
y = ['URL4','news1','news2','URL5','URL6','news1']
I can easily find every URL index and the "news" elements of each URL.
My question is: Is it possible to transform this list into a dictionary in which the URL element is the key and the "news" elements are a list/tuple-value?
Expected Output
z = {'URL1':('news1', 'news2', 'news3'),
'URL2':('news1', 'news2'),
'URL3':('news1'),
'URL4':('news1', 'news2'),
'URL5':(),
'URL6':('news1')}
I've seen a similar question in this post, but it doesn't solve my problem.