Python Forum

Full Version: returning a List of Lists
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
(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
Like this?

x_list = [[(str())]]

print(x_list)
Output:
[['']]
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)
[] [[]] [['']]