Represents a struct-like structure with named and/or unnamed fields.

Structs are similar to collections.namedtuple in that their elements can be accessed by name or by index. However, Structs provide a performance improvement over collections.namedtuple by using a single class to represent values with many different possible structures, rather than creating a brand new class for every new instance.

Structs are commonly used inside Tensorflow Federated as a standard intermediate representation of other structure types, including lists, tuples, dicts, namedtuples, and attr.s classes.


x = Struct([('foo', 10), (None, 20), ('bar', 30)])

len(x) == 3
x[0] == 10
x[1] == 20
x[2] == 30
list(iter(x)) == [10, 20, 30]
dir(x) == ['bar', 'foo'] == 10
x['bar'] == 30

Note that field names are optional, allowing Struct to be used like an ordinary positional tuple.

elements An iterable of element specifications, each being a pair consisting of the element name (either str, or None), and the element value. The order is significant.

TypeError if the elements are not a list, or if any of the items on the list is not a pair with a string at the first position.



View source

Constructs a new Struct with all named elements.


View source

Constructs a new Struct with all unnamed elements.


View source

Return self==value.


View source


View source


View source


View source

Return self!=value.