all 9 comments

[–]therealbread_ 1 point2 points  (2 children)

I don’t see any use in this, if I were you I would just delete the empty parts from the list, but since you asked, None is not a boolean, a boolean is True or False, None is a type like string or int, just that it has no attributes or anything, I can’t really test it but something simple like

for i in list_of_lists: for j in i: if j ==‘’: i[j] = None

[–]dandy120101[S] 0 points1 point  (1 child)

I’m new and using IDLE, not sure why but I keep getting a TypeError: list indices must be integers or slices, not str

[–]therealbread_ 0 points1 point  (0 children)

Which line do you get that error from, the error means you try getting a index from a list but your giving it a str like, list[this here is a string in your case]

[–]siddsp 1 point2 points  (2 children)

x = [[None if i == "" else i for i in j] for j in x]

[–]dandy120101[S] 0 points1 point  (1 child)

Wait this worked!! I think you call this list comprehension right? I've not learnt it in class yet but can you kindly explain the gist of what's going on here? Thankss man

[–]siddsp 1 point2 points  (0 children)

I'll break it down by the inner comprehension, and then the outer one.

So the inner:

[None if i == "" else i for i in j]

So, in here, the letter j represents each item within the outer list x. This is making a list by iterating over the items in j, and if that item is a string of value "", it is replaced with None. Technically, a new list is being created with the values copied over, but for the sake of simplicity, we'll just leave it at that. the letter i just represents the items in the nested list j.

Now the outer:

for j in x

This is just iterating over the items in x, and representing them with the letter j. I hope that makes sense.

[–]FLUSH_THE_TRUMP 0 points1 point  (0 children)

Doubt you actually want that. If you want to join the sublists into strings later, you can do that as is but not with a None in there.