Python Forum
[solved] list of list with one or more empty one
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[solved] list of list with one or more empty one
#4
(May-24-2023, 06:55 AM)paul18fr Wrote: Mprime = [[0] if n == [] else n for n in M]
Try this perhaps
Mprime = [n or [0] for n in M]
or if you dont mind having shared lists
x = [0]
Mprime = [n or x for n in M]
Or don't build a list, use a generator
from itertools import chain
x = [0]
Mprime =  Mprime = np.fromiter(chain.from_iterable(n or x for n in M), dtype=np.uint32)
Mprime = Mprime.reshape((Mprime.size, 1))
Reply


Messages In This Thread
RE: list of list with one or more empty one - by Gribouillis - May-24-2023, 08:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] How to refer to dataframe column name based on a list lorensa74 1 2,389 May-17-2021, 07:02 AM
Last Post: lorensa74
  convert a list of string+bytes into a list of strings (python 3) pacscaloupsu 4 11,035 Mar-17-2020, 07:21 AM
Last Post: markfilan
  search for a part of strinf from list in another list ! evilcode1 3 3,292 Oct-29-2018, 12:07 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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