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_replaceTupleReplaceTupleReplaceTupleReplacetuple_replace
replaces one or more elements of the
input tuple TupleTupleTupleTupletupletuple
and returns them with ReplacedReplacedReplacedReplacedreplacedreplaced
.
At this, IndexIndexIndexIndexindexindex
determines the indices of the elements
and ReplaceTupleReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
the corresponding values to replace.
The parameter IndexIndexIndexIndexindexindex
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 ReplaceTupleReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
contains only
one value, this value will be replaced at all indices of IndexIndexIndexIndexindexindex
.
If a value of IndexIndexIndexIndexindexindex
is greater than the length of the input
tuple TupleTupleTupleTupletupletuple
, ReplacedReplacedReplacedReplacedreplacedreplaced
will be extended accordingly and
initialized with zeros. For example, if TupleTupleTupleTupletupletuple
contains [1],
IndexIndexIndexIndexindexindex
contains the values [2,4], and ReplaceTupleReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
contains the values [3,5], ReplacedReplacedReplacedReplacedreplacedreplaced
will be [1,0,3,0,5].
It is allowed to mix strings and numbers in the input tuples
TupleTupleTupleTupletupletuple
and ReplaceTupleReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
.
Exception: Empty input tuples
If either IndexIndexIndexIndexindexindex
or ReplaceTupleReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_tuple
is empty and the other is
not, an exception is raised. If both are empty, the output tuple
ReplacedReplacedReplacedReplacedreplacedreplaced
corresponds to the input TupleTupleTupleTupletupletuple
. If both are
empty, but the input TupleTupleTupleTupletupletuple
is not, the empty tuple will be
extended as described above.
HDevelop In-line Operation
HDevelop provides an in-line operation for tuple_replacetuple_replaceTupleReplaceTupleReplaceTupleReplacetuple_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
TupleTupleTupleTupletupletuple
(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.
IndexIndexIndexIndexindexindex
(input_control) integer(-array) →
HTupleMaybeSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)
Index/Indices of elements to be replaced.
ReplaceTupleReplaceTupleReplaceTupleReplaceTuplereplaceTuplereplace_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.
ReplacedReplacedReplacedReplacedreplacedreplaced
(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_selectTupleSelectTupleSelectTupleSelecttuple_select
,
tuple_first_ntuple_first_nTupleFirstNTupleFirstNTupleFirstNtuple_first_n
,
tuple_last_ntuple_last_nTupleLastNTupleLastNTupleLastNtuple_last_n
,
tuple_select_masktuple_select_maskTupleSelectMaskTupleSelectMaskTupleSelectMasktuple_select_mask
,
tuple_str_bit_selecttuple_str_bit_selectTupleStrBitSelectTupleStrBitSelectTupleStrBitSelecttuple_str_bit_select
,
tuple_concattuple_concatTupleConcatTupleConcatTupleConcattuple_concat
,
tuple_select_ranktuple_select_rankTupleSelectRankTupleSelectRankTupleSelectRanktuple_select_rank
See also
tuple_removetuple_removeTupleRemoveTupleRemoveTupleRemovetuple_remove
,
tuple_inserttuple_insertTupleInsertTupleInsertTupleInserttuple_insert
Module
Foundation