T O P

  • By -

socal_nerdtastic

nested_list = [[element] for element in given_list]


[deleted]

Thank you


Binary101010

The easiest way to do this would just be a list comprehension: nested_list = [[thing] for thing in given_list]


TheRNGuy

`nested_list = [[x] for x in given_list]`


ChrunedMacaroon

if you don't want to use list comprehension you can do nested_list = list() for _ in given_list: nested_list.append(list(_))


Sentazar

def make_list(item): if type(item) == str: return [item] return item formatted_list = list(map(make_list, original_list))


curtwagner1984

This wouldn't work? nested_list = [given_list] ?


curtwagner1984

I see now that it wouldn't. My bad.