### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >

# 54. `olist` — Some convenient shortcuts for common list operations.

While most of these functions look (and work) like set operations, their result differs from using Python builtin Sets in that they preserve the order of the items in the lists.

`Classes defined in module olist`

`Functions defined in module olist`

`olist.``roll`(a, n=1)

  Roll the elements of a list n positions forward (backward if n < 0)

`olist.``union`(a, b)

  Return a list with all items in a or in b, in the order of a,b.

`olist.``difference`(a, b)

  Return a list with all items in a but not in b, in the order of a.

`olist.``symdifference`(a, b)

  Return a list with all items in a or b but not in both.

`olist.``intersection`(a, b)

  Return a list with all items in a and in b, in the order of a.

`olist.``concatenate`(a)

  Concatenate a list of lists

`olist.``flatten`(a, recurse=False)

  Flatten a nested list.

  By default, lists are flattened one level deep. If recurse=True, flattening recurses through all sublists.

      >>> flatten([[[3.,2,],6.5,],[5],6,'hi'])
      [[3.0, 2], 6.5, 5, 6, 'hi']
      >>> flatten([[[3.,2,],6.5,],[5],6,'hi'],True)
      [3.0, 2, 6.5, 5, 6, 'hi']

`olist.``select`(a, b)

  Return a subset of items from a list.

  Returns a list with the items of a for which the index is in b.

`olist.``collectOnLength`(items, return_indices=False)

  Collect items of a list in separate bins according to the item length.

  items is a list of items of any type having the len() method. The items are put in separate lists according to their length.

  The return value is a dict where the keys are item lengths and the values are lists of items with this length.

  If return_indices is True, a second dict is returned, with the same keys, holding the original indices of the items in the lists.

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >