Susu (Sequence)¶
-
class
mochila.
Sequence
(iterable=())¶ A Sequence is an enumerated collection of items. The order in which the items appear in the collection matters and the same item can appear multiple times.
A sequence behaves as the Python built-in list type. The main difference is that item access by index additionally supports an iterable as the index. In this case the result will be a Sequence of the items corresponding to those indices.
>>> m = Sequence(['a','b','c']) # a new Sequence >>> m[1] 'b' >>> m[[0,2]] ['a', 'c']
Sequences can be constructed using the type constructor Sequence() or Sequence(iterable). The constructor builds a Sequence whose items are the same and in the same order as iterable‘s items. iterable may be either a sequence, a container that supports iteration, or an iterator object. For example, Sequence(‘abc’) returns [‘a’, ‘b’, ‘c’] and Sequence((1, 2, 3)) returns [1, 2, 3]. If no argument is given, the constructor creates a new empty Sequence, [].
Note that the default representation of a Sequence is the same as for a list.
Parameters: iterable – An iterable used to instantiate the Sequence