konrad
konrad

Reputation: 3716

Append multiple items into list of lists in Python

I am trying to append items into lists of list but instead i am getting an equivalent of extend().

doc = __doc__
result = []

collector = FilteredWorksetCollector(doc)
user_worksets = collector.OfKind(WorksetKind.UserWorkset)
for i in user_worksets:
    result.append(i.Name)
    result.append(i.Kind)
OUT = result

I would like to get a list that looks like this: [[name, name, name],[kind, kind, kind]]

thank you,

Upvotes: 1

Views: 270

Answers (1)

John Kugelman
John Kugelman

Reputation: 362037

OUT = [[i.Name for i in user_worksets], [i.Kind for i in user_worksets]]

Upvotes: 4

Related Questions