0

我有一个清单:

['EFJAJCOWSS', 'SDGKSRFDFF', 'ASRJDUSKLK', 'HEANDNDJWA', 'ANSDNCNEOP', 'PMSNFHHEJE', 'JEPQLYNXDL']

从这个列表中我如何创建一个子列表:

[['EFJAJCOWSS'], ['SDGKSRFDFF'], ['ASRJDUSKLK'], ['HEANDNDJWA'], ['ANSDNCNEOP'], ['PMSNFHHEJE'], ['JEPQLYNXDL']]

在 Python 中使用列表推导?

4

1 回答 1

1
In [45]: lis=['EFJAJCOWSS', 'SDGKSRFDFF', 'ASRJDUSKLK', 'HEANDNDJWA', 'ANSDNCNEOP', 'PMSNFHHEJE', 'JEPQLYNXDL']

In [46]: [[x] for x in lis]
Out[46]: 
[['EFJAJCOWSS'],
 ['SDGKSRFDFF'],
 ['ASRJDUSKLK'],
 ['HEANDNDJWA'],
 ['ANSDNCNEOP'],
 ['PMSNFHHEJE'],
 ['JEPQLYNXDL']]

或使用map()

In [47]: map(lambda x:[x],lis)
Out[47]: 
[['EFJAJCOWSS'],
 ['SDGKSRFDFF'],
 ['ASRJDUSKLK'],
 ['HEANDNDJWA'],
 ['ANSDNCNEOP'],
 ['PMSNFHHEJE'],
 ['JEPQLYNXDL']]
于 2012-10-31T23:55:42.020 回答