Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
returning a List of Lists
#1
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.
Reply
#2
(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
Reply
#3
Like this?

x_list = [[(str())]]

print(x_list)
Output:
[['']]
Sig:
>>> import this

The UNIX philosophy: "Do one thing, and do it well."

"The danger of computers becoming like humans is not as great as the danger of humans becoming like computers." :~ Konrad Zuse

"Everything should be made as simple as possible, but not simpler." :~ Albert Einstein
Reply
#4
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)
[] [[]] [['']]
rob101 likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  list.sort() returning None SmallCoder14 8 600 Mar-19-2024, 09:49 PM
Last Post: SmallCoder14
  List all possibilities of a nested-list by flattened lists sparkt 1 923 Feb-23-2023, 02:21 PM
Last Post: sparkt
  user input values into list of lists tauros73 3 1,075 Dec-29-2022, 05:54 PM
Last Post: deanhystad
  Creating list of lists, with objects from lists sgrinderud 7 1,657 Oct-01-2022, 07:15 PM
Last Post: Skaperen
  How to efficiently average same entries of lists in a list xquad 5 2,139 Dec-17-2021, 04:44 PM
Last Post: xquad
  sorting a list of lists by an element leapcfm 3 1,891 Sep-10-2021, 03:33 PM
Last Post: leapcfm
  behavior list of lists roym 5 2,114 Jul-04-2021, 04:43 PM
Last Post: roym
  List of lists - merge sublists with common elements medatib531 1 3,416 May-09-2021, 07:49 AM
Last Post: Gribouillis
  Sort List of Lists by Column Nju 1 11,581 Apr-13-2021, 11:59 PM
Last Post: bowlofred
  Creating list of lists from generator object t4keheart 1 2,219 Nov-13-2020, 04:59 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020