从列表元素创建新列表 [英] Create new lists from elements of a list

查看:59
本文介绍了从列表元素创建新列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以使用另一个列表的元素中的名称来创建多个列表.

Is there a way to create multiple lists with names from elements of another list.

例如:

names=["Rob","Mark","Steve"]

是否可以创建类似于以下内容的列表:

Is there a way to create lists like:

Rob=[]
Mark=[]
Steve=[]

推荐答案

一种明显的方式是这样的:

The one obvious way is like this:

>>> names = ["Rob","Mark","Steve"]
>>> lists = {name: [] for name in names}
>>> print lists
{'Steve': [], 'Rob': [], 'Mark': []}

这篇关于从列表元素创建新列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆