tuple_replaceT_tuple_replaceTupleReplaceTupleReplacetuple_replace (Operator)
Name
tuple_replaceT_tuple_replaceTupleReplaceTupleReplacetuple_replace
— Replaces one or more elements of a tuple.
Signature
def tuple_replace(tuple: MaybeSequence[Union[float, int, str]], index: MaybeSequence[int], replace_tuple: MaybeSequence[Union[float, int, str]]) -> Sequence[Union[float, int, str]]
Description
tuple_replacetuple_replaceTupleReplaceTupleReplacetuple_replace
replaces one or more elements of the
input tuple TupleTupleTupletupletuple
and returns them with ReplacedReplacedReplacedreplacedreplaced
.
At this, IndexIndexIndexindexindex
determines the indices of the elements
and ReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
the corresponding values to replace.
The parameter IndexIndexIndexindexindex
must contain one or more integer values
(any floating point number must represent an integer value without
fraction). Indices of tuple elements start at 0. Therefore, the first
tuple element has got the index 0. If ReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
contains only
one value, this value will be replaced at all indices of IndexIndexIndexindexindex
.
If a value of IndexIndexIndexindexindex
is greater than the length of the input
tuple TupleTupleTupletupletuple
, ReplacedReplacedReplacedreplacedreplaced
will be extended accordingly and
initialized with zeros. For example, if TupleTupleTupletupletuple
contains [1],
IndexIndexIndexindexindex
contains the values [2,4], and ReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
contains the values [3,5], ReplacedReplacedReplacedreplacedreplaced
will be [1,0,3,0,5].
It is allowed to mix strings and numbers in the input tuples
TupleTupleTupletupletuple
and ReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
.
Exception: Empty input tuples
If either IndexIndexIndexindexindex
or ReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
is empty and the other is
not, an exception is raised. If both are empty, the output tuple
ReplacedReplacedReplacedreplacedreplaced
corresponds to the input TupleTupleTupletupletuple
. If both are
empty, but the input TupleTupleTupletupletuple
is not, the empty tuple will be
extended as described above.
HDevelop In-line Operation
HDevelop provides an in-line operation for tuple_replacetuple_replaceTupleReplaceTupleReplacetuple_replace
,
which can be used in an expression in the following syntax:
Replaced := replace(Tuple, Index, ReplaceTuple)
Execution Information
- Multithreading type: independent (runs in parallel even with exclusive operators).
- Multithreading scope: global (may be called from any thread).
- Processed without parallelization.
Parameters
TupleTupleTupletupletuple
(input_control) tuple(-array) →
HTupleMaybeSequence[Union[float, int, str]]HTupleHtuple (integer / real / string) (int / long / double / string) (Hlong / double / HString) (Hlong / double / char*)
Input tuple.
IndexIndexIndexindexindex
(input_control) integer(-array) →
HTupleMaybeSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)
Index/Indices of elements to be replaced.
ReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
(input_control) tuple(-array) →
HTupleMaybeSequence[Union[float, int, str]]HTupleHtuple (integer / real / string) (int / long / double / string) (Hlong / double / HString) (Hlong / double / char*)
Element(s) to replace.
ReplacedReplacedReplacedreplacedreplaced
(output_control) tuple-array →
HTupleSequence[Union[float, int, str]]HTupleHtuple (integer / real / string) (int / long / double / string) (Hlong / double / HString) (Hlong / double / char*)
Tuple with replaced elements.
Alternatives
tuple_selecttuple_selectTupleSelectTupleSelecttuple_select
,
tuple_first_ntuple_first_nTupleFirstNTupleFirstNtuple_first_n
,
tuple_last_ntuple_last_nTupleLastNTupleLastNtuple_last_n
,
tuple_select_masktuple_select_maskTupleSelectMaskTupleSelectMasktuple_select_mask
,
tuple_str_bit_selecttuple_str_bit_selectTupleStrBitSelectTupleStrBitSelecttuple_str_bit_select
,
tuple_concattuple_concatTupleConcatTupleConcattuple_concat
,
tuple_select_ranktuple_select_rankTupleSelectRankTupleSelectRanktuple_select_rank
See also
tuple_removetuple_removeTupleRemoveTupleRemovetuple_remove
,
tuple_inserttuple_insertTupleInsertTupleInserttuple_insert
Module
Foundation