从python中的集合中获取列表 [英] Get a list from a set in python

查看:186
本文介绍了从python中的集合中获取列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何在Python中以list[]形式获取set()的内容?

Ho do I get the contents of a set() in list[] form in Python?

我需要执行此操作,因为我需要将集合保存在Google App Engine中,并且Entity属性类型可以是列表,但不能是集合.我知道我可以遍历整个过程,但是似乎应该有一种捷径或最佳做法"来做到这一点.

I need to do this because I need to save the collection in Google App Engine and Entity property types can be lists, but not sets. I know I can just iterate over the whole thing, but it seems like there should be a short-cut, or "best practice" way to do this.

推荐答案

>>> s = set([1, 2, 3])
>>> list(s)
[1, 2, 3]

请注意,您获得的列表没有明确的顺序.

Note that the list you get doesn't have a defined order.

这篇关于从python中的集合中获取列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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