我有一个清单:
['EFJAJCOWSS', 'SDGKSRFDFF', 'ASRJDUSKLK', 'HEANDNDJWA', 'ANSDNCNEOP', 'PMSNFHHEJE', 'JEPQLYNXDL']
从此列表中我如何创建子列表:
[['EFJAJCOWSS'], ['SDGKSRFDFF'], ['ASRJDUSKLK'], ['HEANDNDJWA'], ['ANSDNCNEOP'], ['PMSNFHHEJE'], ['JEPQLYNXDL']]
在Python中使用列表推导?
答案 0 :(得分: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']]