Robert Johnstone
Robert Johnstone

Reputation: 5371

Making a nested list from a list in Python

How do I make the following list:

nested_list = [['dave','dave'],['ian','ian'],['james','james']]

from:

list = ['dave', 'ian', 'james']

Upvotes: 2

Views: 49

Answers (1)

wflynny
wflynny

Reputation: 18521

nested_list = [[x, x] for x in list]

or, if you don't mind tuples,

nested_list = zip(list, list)

Upvotes: 7

Related Questions