Skip to content

Commit

Permalink
Update nest.py (#22590)
Browse files Browse the repository at this point in the history
  • Loading branch information
MahadShahid8 authored Sep 3, 2023
1 parent 3a644e9 commit ea17de0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion ivy/functional/ivy/nest.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,35 @@ def set_nest_at_index(


@handle_exceptions
def insert_into_nest_at_index(nest: Iterable, index: Tuple, value, /) -> None:
def insert_into_nest_at_index(nest: Iterable, index: Tuple, value) -> None:
"""
Recursively inserts a value into a nested data structure at a specified index.
This function traverses a nested data structure and inserts the provided `value`
at the specified `index`.
Parameters
----------
nest : Iterable
The nested data structure.
index : Tuple
The index specifying the location where the `value` should be inserted.
value : object
The value to be inserted.
Returns
-------
None
Examples
--------
>>> nest = [[1, 2], [3, 4]]
>>> index = (1, 1)
>>> value = 99
>>> insert_into_nest_at_index(nest, index, value)
>>> print(nest)
[[1, 2], [3, 99, 4]]
"""
if len(index) == 1:
idx = index[0]
if isinstance(nest, list):
Expand Down

0 comments on commit ea17de0

Please sign in to comment.