I am writing a program to find the most similar words for a list of input words using Gensim for word2vec.
Example: input_list = ["happy", "beautiful"]
Further, I use a for loop
to iterate over the list and store the output in a list data structure using the .append()
function.
The final list is a list of lists having tuples. See below
results = [[('glad', 0.7408891320228577),
('pleased', 0.6632170081138611)],
[('gorgeous', 0.8353002667427063),
('lovely', 0.8106935024261475)]]
My question is how to separate the list of lists into independent lists? I followed answers from 1 and 2 which suggest unpacking like a, b = results
.
But this is possible when you know the number of input elements (here 2).
Expected Output (based on above):
list_a = [('glad', 0.7408891320228577), ('pleased', 0.6632170081138611)]
list_b = [('gorgeous', 0.8353002667427063), ('lovely', 0.8106935024261475)]
But, if the number of input elements is always variable, say 4 or 5, then how do we unpack and get a reference to the independent lists at run-time?
Or what is a better data structure to store the above results so that unpacking or further processing is friendlier?
Kindly help.