+ 1
creating a numpy array from lists with list names
Hi, I would like to create a list of lists (numpy array) with list names, mean and list length. Example: list1 = [1,2,3] list2 = [4,5,6,7,8] list3 = [7,8,9,10,11,12,13] Code: list_of_lists = [list1, list2, list3] final_numpy = ['list_name', 'mean', 'list length'] for each in list_of_lists: final_numpy.append([..., mean(each), len(each)]) I would like to have an output like this: final_numpy = [['list_name', 'mean', 'list length'], ['list1', 2, 3], ['list2', 6, 5], ['list3', 10, 7]] I am almost there but don't know how to include the list name in the loop. please help
5 ответов
+ 2
+Marek Kluczewski i literally re-wrote it for you already lol
+ 2
Thank you for your help.
I have a question though. Is there an automated way to include list names as strings? I thought that maybe there is a function which can get the list name from the list while looping through various it.
+ 2
+Marek Kluczewski It's not possible. Names hold references to memory, but memory does not hold references to names which reference them.
+ 1
Here i rewrote the code for you and it's working :-)
https://code.sololearn.com/cvjWaP1UO3M9/#py
The problem is when you have the name of a list in another list, the list item is replaced with the contents of the list. For example,
print(list_of_lists[list1])
is the same as:
print(list1)
- 1
What do you mean exactly? I haven't tried it