Skip to content

remove_if_eq

async def remove_if_eq( name:str, *,
                        start: int = 0,
                        stop: int = None,
                        val: str|int|float) -> int
Search items in range: [start, stop), removing those with value equal to val.

start and stop use the same rules as get_range(), so negative and positive values are permitted, but they must translate to indices where start < stop.

Note

No gaurantees on behaviour if val is not the same type as when the list was created. This will be addressed in a future release.

Returns

Length of the list after nodes removed.

Examples

await list.create('rmv_if', type='int')

await list.add('rmv_if', [0,1,2,5,5,5,6,7,8,9,7,7,10])
print(await list.get_n('rmv_if'))

await list.remove_if_eq('rmv_if', start=0, stop=7, val=5)
print(await list.get_n('rmv_if'))

await list.remove_if_eq('rmv_if', start=-3, val=7)
print(await list.get_n('rmv_if'))
Output
[0, 1, 2, 5, 5, 5, 6, 7, 8, 9, 7, 7, 10]
[0, 1, 2, 6, 7, 8, 9, 7, 7, 10]
[0, 1, 2, 6, 7, 8, 9, 10]