Python Forum
returning a List of Lists - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: returning a List of Lists (/thread-38558.html)



returning a List of Lists - nafshar - Oct-28-2022

I am trying to return an empty list of lists from a function so that, when printed, will look like : [[""]]

But a return like the following result in a printing: []

return [[]]*1

return [[]]
I would be grateful for any suggestion.


RE: returning a List of Lists - nafshar - Oct-28-2022

(Oct-28-2022, 05:36 PM)nafshar Wrote: I am trying to return an empty list of lists from a function so that, when printed, will look like : [[""]]

But a return like the following result in a printing: []

return [[]]*1

return [[]]
I would be grateful for any suggestion.

Sorry Guys. Looks like this code actually does work. I was just skipping over the statement !! - Thank you


RE: returning a List of Lists - rob101 - Oct-28-2022

Like this?

x_list = [[(str())]]

print(x_list)
Output:
[['']]



RE: returning a List of Lists - deanhystad - Oct-28-2022

There is no such thing as an empty list of lists. There is an empty list [], there is an empty list in a list [[]], and there is an empty string in a list that is in another list [[""]]. The last having no empty lists at all.
empty_list = []
empty_list_in_list = [[]]
empty_str_in_list_in_list = [[""]]
print(empty_list, empty_list_in_list, empty_str_in_list_in_list)
[] [[]] [['']]