8.6.3. tuplelist

class tuplelist

Represents a list of tuples. After an index is created, you can quickly match the tuples in the list by specifying the query criteria. For example:

li = tuplelist()
li.append((1, 2, 'sum is 3'))
li.append((2, 2, 'sum is 4'))
# matches all records
li.select('*', 2, '*')
# matches the first record
li.select(1)
# matches the second
li.select('*', '*', 'sum is 4')record.

Methods

__init__()

Construct a tuplelist

clean()

Clear the index of the tuplelist to release memory

select()

Match scalar or tuple from tuplelist

__init__(li, wildcard)

Construct a tuplelist

Parameters
  • li – The array of data that is initially appended.

  • wildcard – The string that matches any value. Default value ‘*’

example:

li = tuplelist([(1, 2), (3, 4)], wildcard='@')

Note

The elements of the input array, which can be scalar or tuple. If it is a tuple, it must have the same length.

clean()

Clear the index of the tuplelist to release memory.

Note

After the index is cleared, the index will be rebuilt when a query is performed again.

select(*query=[])

Match scalar or tuple from tuplelist

Parameters

*query=[]

The tuple pattern to match.

example:

li = tuplelist([(1, 2, 3), (2, 2, 3)])
li.select('*', 2, 3)
li.select(1)
li.select(1, 2)

Note

Calling select triggers the creation of index, but modifying the tuplelist clears the index. Avoid frequent index creation.