Skip to main content
Version: 0.3.x

pop_item_of_object

FunctionPrivateSource

data_selected: Any = pop_item_of_object(data: Any, index: Any)

Run val = data[index]; del data[index]; return val supposing that data is abitrary and index can be a one-value sequence.

warning

Note that index is not a route. If it is a sequence, it should only contain one element.

Arguments

Requires

ArgumentTypeRequired
Description
dataAnyThe whole data to be indexed.
indexAnyThe index to be used for locating the part to be removed. It can be a number, or keyword, or a one-value sequence like [0].

Returns

ArgumentType
Description
data_selectedAnyThe part of the data located by the given index and removed from the data.

Examples

Remove a part of the whole data

remove_a_part_of_data.py
import pprint
from dash_json_grid.mixins import pop_item_of_object

data = {
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 1111.55,
"batters": {
"batter": [
{"id": "1001", "type": "Regular"},
{"id": "1002", "type": "Chocolate"},
{"id": "1003", "type": "Blueberry"},
{"id": "1004", "type": "Devil's Food"},
]
},
"topping": [
{"id": "5001", "type": "None"},
{"id": "5002", "type": "Glazed"},
{"id": "5005", "type": "Sugar"},
{"id": "5007", "type": "Powdered Sugar"},
{"id": "5006", "type": "Chocolate with Sprinkles"},
{"id": "5003", "type": "Chocolate"},
{"id": "5004", "type": "Maple"},
],
}

route = "topping"

removed = pop_item_of_object(data, route)
pprint.pprint(data)
pprint.pprint(removed)