Skip to content

ConfigSet from arbitrary iterable & subscriptable ConfigSet #229

Open
@gelzinyte

Description

@gelzinyte

Moving discussion from PR #222 here. (link to the thread)

First, have an __gettitem__ method

from itertools import islice
.
.
.
  def __getitem__(self, arg):
      if isinstance(arg, slice):
          return islice(self, arg.start, arg.stop, arg.step)
      elif isinstance(arg, int):
          return list(islice(self, arg, arg + 1, 1))[0]
      else:
          raise TypeError

Second, make it so ConfigSet can be constructed from an arbitrary iterable.

This came from wanting a (slightly) simpler interface, where ConfigSet behaves more like a list:

subsample_configset = ConfigSet(in_configset[::2])

Currently that can be done by converting to list and back

subsample_configset = ConfigSet(list(in_configset)[::2])

Not sure if this simpler interface is worth the changes, but being able to create ConfigSets from arbitrary iterable/generator might be useful?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions