Operations with arrays

Accessing array items

In PonyORM array indexes are zero-based, as in Python. It is possible to use negative indexes to access array from the end. You can also use array slices.

Select specific item of array

  1. select(p.tags[2] for p in Product)[:] # third element
  2. select(p.tags[-1] for p in Product)[:] # last element

Using slice

  1. select(p.tags[:5] for p in Product)[:] # first five elements

Note

Steps are not supported for slices.

Check if item or list of items in or not in array

  1. select(p for p in Product if 'apple' in p.tags)[:]
  2. select(p for p in Product if ['LCD', 'DVD', 'SSD'] in p.tags)[:]

Change array’s items

  1. product = Product.select().first()
  2. product.tags.remove('factory-new')
  3. product.tags.append('reconstructed')