[英]How do you create a class, or function in python that allows you to make a sequence type with specific characteristics
1) My goal is to create a sequence that is a list that contains ordered dictionaries. 1)我的目标是创建一个序列,它是一个包含有序字典的列表。 The only problem for me will be described below.
对我来说唯一的问题将在下面描述。
OrderedDict()
doesn't show up.OrderedDict()
类的东西没有出现,我也希望如此。 However, I do not mind if it shows up in return values.list(index0, index1, ... etc)
but instead it shows up as [index0, index1, ... etc]
.list(index0, index1, ... etc)
而是显示为[index0, index1, ... etc]
。 That is what I mean.point = {'height': 1, 'weight': 3, 'age': 5, etc}
<- It could be brackets or braces or parentheses. point = {'height': 1, 'weight': 3, 'age': 5, etc}
<- 可以是方括号、大括号或圆括号。 Just some type of "end mark", but I preferably would like it to be in {} and having key value pairs indicated by key: value and have them separated by commas.只是某种类型的“结束标记”,但我更希望它在 {} 中,并且具有由 key: value 指示的键值对,并用逗号分隔它们。
what_i_am_looking_for = [point0, point1, point2, point3, ... etc]
what_i_am_looking_for =
[point0, point1, point2, point3, ... etc]
In Python 3.6, the ordinary dict
implementation was re-written and maintains key insertion order like OrderedDict
, but was considered an implementation detail.在 Python 3.6 中,普通的
dict
实现被重写,并像OrderedDict
一样维护键插入顺序,但被认为是一个实现细节。 Python 3.7 made this feature an official part of the language spec, so if you use Python 3.6+ just use dict
instead of OrderedDict
if you don't care about backward-compatibility with Python 3.5 or earlier. Python 3.7 将此功能作为语言规范的官方部分,因此如果您使用 Python 3.6+,如果您不关心与 Python 3.5 或更早版本的向后兼容性,只需使用
dict
而不是OrderedDict
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.