class_docstr: Class representing a sequence of vertices in the graph.
  
  This class is most easily accessed by the C{vs} field of the
  L{Graph} object, which returns an ordered sequence of all vertices in
  the graph. The vertex sequence can be refined by invoking the
  L{VertexSeq.select()} method. L{VertexSeq.select()} can also be
  accessed by simply calling the L{VertexSeq} object.
  
  An alternative way to create a vertex sequence referring to a given
  graph is to use the constructor directly:
  
    >>> g = Graph.Full(3)
    >>> vs = VertexSeq(g)
    >>> restricted_vs = VertexSeq(g, [0, 1])
  
  The individual vertices can be accessed by indexing the vertex sequence
  object. It can be used as an iterable as well, or even in a list
  comprehension:
  
    >>> g=Graph.Full(3)
    >>> for v in g.vs:
    ...   v["value"] = v.index ** 2
    ...
    >>> [v["value"] ** 0.5 for v in g.vs]
    [0.0, 1.0, 2.0]
  
  The vertex set can also be used as a dictionary where the keys are the
  attribute names. The values corresponding to the keys are the values
  of the given attribute for every vertex selected by the sequence.
  
    >>> g=Graph.Full(3)
    >>> for idx, v in enumerate(g.vs):
    ...   v["weight"] = idx*(idx+1)
    ...
    >>> g.vs["weight"]
    [0, 2, 6]
    >>> g.vs.select(1,2)["weight"] = [10, 20]
    >>> g.vs["weight"]
    [0, 10, 20]
  
  If you specify a sequence that is shorter than the number of vertices in
  the VertexSeq, the sequence is reused:
  
    >>> g = Graph.Tree(7, 2)
    >>> g.vs["color"] = ["red", "green"]
    >>> g.vs["color"]
    ['red', 'green', 'red', 'green', 'red', 'green', 'red']
  
  You can even pass a single string or integer, it will be considered as a
  sequence of length 1:
  
    >>> g.vs["color"] = "red"
    >>> g.vs["color"]
    ['red', 'red', 'red', 'red', 'red', 'red', 'red']
  
  Some methods of the vertex sequences are simply proxy methods to the
  corresponding methods in the L{Graph} object. One such example is
  C{VertexSeq.degree()}:
  
    >>> g=Graph.Tree(7, 2)
    >>> g.vs.degree()
    [2, 3, 3, 1, 1, 1, 1]
    >>> g.vs.degree() == g.degree()
    True
docstr: Selects a subset of the vertex sequence based on some criteria
  
  The selection criteria can be specified by the positional and the keyword
  arguments. Positional arguments are always processed before keyword
  arguments.
  
    - If the first positional argument is C{None}, an empty sequence is
      returned.
  
    - If the first positional argument is a callable object, the object
      will be called for every vertex in the sequence. If it returns
      C{True}, the vertex will be included, otherwise it will
      be excluded.
  
    - If the first positional argument is an iterable, it must return
      integers and they will be considered as indices of the current
      vertex set (NOT the whole vertex set of the graph -- the
      difference matters when one filters a vertex set that has
      already been filtered by a previous invocation of
      L{VertexSeq.select()}. In this case, the indices do not refer
      directly to the vertices of the graph but to the elements of
      the filtered vertex sequence.
  
    - If the first positional argument is an integer, all remaining
      arguments are expected to be integers. They are considered as
      indices of the current vertex set again.
  
  Keyword arguments can be used to filter the vertices based on their
  attributes. The name of the keyword specifies the name of the attribute
  and the filtering operator, they should be concatenated by an
  underscore (C{_}) character. Attribute names can also contain
  underscores, but operator names don't, so the operator is always the
  largest trailing substring of the keyword name that does not contain
  an underscore. Possible operators are:
  
    - C{eq}: equal to
  
    - C{ne}: not equal to
  
    - C{lt}: less than
  
    - C{gt}: greater than
  
    - C{le}: less than or equal to
  
    - C{ge}: greater than or equal to
  
    - C{in}: checks if the value of an attribute is in a given list
  
    - C{notin}: checks if the value of an attribute is not in a given
      list
  
  For instance, if you want to filter vertices with a numeric C{age}
  property larger than 200, you have to write:
  
    >>> g.vs.select(age_gt=200)                   #doctest: +SKIP
  
  Similarly, to filter vertices whose C{type} is in a list of predefined
  types:
  
    >>> list_of_types = ["HR", "Finance", "Management"]
    >>> g.vs.select(type_in=list_of_types)        #doctest: +SKIP
  
  If the operator is omitted, it defaults to C{eq}. For instance, the
  following selector selects vertices whose C{cluster} property equals
  to 2:
  
    >>> g.vs.select(cluster=2)                    #doctest: +SKIP
  
  In the case of an unknown operator, it is assumed that the
  recognized operator is part of the attribute name and the actual
  operator is C{eq}.
  
  Attribute names inferred from keyword arguments are treated specially
  if they start with an underscore (C{_}). These are not real attributes
  but refer to specific properties of the vertices, e.g., its degree.
  The rule is as follows: if an attribute name starts with an underscore,
  the rest of the name is interpreted as a method of the L{Graph} object.
  This method is called with the vertex sequence as its first argument
  (all others left at default values) and vertices are filtered
  according to the value returned by the method. For instance, if you
  want to exclude isolated vertices:
  
    >>> g = Graph.Famous("zachary")
    >>> non_isolated = g.vs.select(_degree_gt=0)
  
  For properties that take a long time to be computed (e.g., betweenness
  centrality for large graphs), it is advised to calculate the values
  in advance and store it in a graph attribute. The same applies when
  you are selecting based on the same property more than once in the
  same C{select()} call to avoid calculating it twice unnecessarily.
  For instance, the following would calculate betweenness centralities
  twice:
  
    >>> edges = g.vs.select(_betweenness_gt=10, _betweenness_lt=30)
  
  It is advised to use this instead:
  
    >>> g.vs["bs"] = g.betweenness()
    >>> edges = g.vs.select(bs_gt=10, bs_lt=30)
  
  @return: the new, filtered vertex sequence
docstr_tok: ["Selects","a","subset","of","the","vertex","sequence","based","on","some","criteria","The","selection","criteria","can","be","specified","by","the","positional","and","the","keyword","arguments",".","Positional","arguments","are","always","processed","before","keyword","arguments",".","-","If","the","first","positional","argument","is","C","{","None","}",",","an","empty","sequence","is","returned",".","-","If","the","first","positional","argument","is","a","callable","object",",","the","object","will","be","called","for","every","vertex","in","the","sequence",".","If","it","returns","C","{","True","}",",","the","vertex","will","be","included",",","otherwise","it","will","be","excluded",".","-","If","the","first","positional","argument","is","an","iterable",",","it","must","return","integers","and","they","will","be","considered","as","indices","of","the","current","vertex","set","(","NOT","the","whole","vertex","set","of","the","graph","--","the","difference","matters","when","one","filters","a","vertex","set","that","has","already","been","filtered","by","a","previous","invocation","of","L","{","VertexSeq.select","(",")","}",".","In","this","case",",","the","indices","do","not","refer","directly","to","the","vertices","of","the","graph","but","to","the","elements","of","the","filtered","vertex","sequence",".","-","If","the","first","positional","argument","is","an","integer",",","all","remaining","arguments","are","expected","to","be","integers",".","They","are","considered","as","indices","of","the","current","vertex","set","again",".","Keyword","arguments","can","be","used","to","filter","the","vertices","based","on","their","attributes",".","The","name","of","the","keyword","specifies","the","name","of","the","attribute","and","the","filtering","operator",",","they","should","be","concatenated","by","an","underscore","(","C","{","_","}",")","character",".","Attribute","names","can","also","contain","underscores",",","but","operator","names","do","n't",",","so","the","operator","is","always","the","largest","trailing","substring","of","the","keyword","name","that","does","not","contain","an","underscore",".","Possible","operators","are",":","-","C","{","eq","}",":","equal","to","-","C","{","ne","}",":","not","equal","to","-","C","{","lt","}",":","less","than","-","C","{","gt","}",":","greater","than","-","C","{","le","}",":","less","than","or","equal","to","-","C","{","ge","}",":","greater","than","or","equal","to","-","C","{","in","}",":","checks","if","the","value","of","an","attribute","is","in","a","given","list","-","C","{","notin","}",":","checks","if","the","value","of","an","attribute","is","not","in","a","given","list","For","instance",",","if","you","want","to","filter","vertices","with","a","numeric","C","{","age","}","property","larger","than","200",",","you","have","to","write",":",">",">",">","g.vs.select","(","age_gt=200",")","#","doctest",":","+SKIP","Similarly",",","to","filter","vertices","whose","C","{","type","}","is","in","a","list","of","predefined","types",":",">",">",">","list_of_types","=","[","``","HR","''",",","``","Finance","''",",","``","Management","''","]",">",">",">","g.vs.select","(","type_in=list_of_types",")","#","doctest",":","+SKIP","If","the","operator","is","omitted",",","it","defaults","to","C","{","eq","}",".","For","instance",",","the","following","selector","selects","vertices","whose","C","{","cluster","}","property","equals","to","2",":",">",">",">","g.vs.select","(","cluster=2",")","#","doctest",":","+SKIP","In","the","case","of","an","unknown","operator",",","it","is","assumed","that","the","recognized","operator","is","part","of","the","attribute","name","and","the","actual","operator","is","C","{","eq","}",".","Attribute","names","inferred","from","keyword","arguments","are","treated","specially","if","they","start","with","an","underscore","(","C","{","_","}",")",".","These","are","not","real","attributes","but","refer","to","specific","properties","of","the","vertices",",","e.g.",",","its","degree",".","The","rule","is","as","follows",":","if","an","attribute","name","starts","with","an","underscore",",","the","rest","of","the","name","is","interpreted","as","a","method","of","the","L","{","Graph","}","object",".","This","method","is","called","with","the","vertex","sequence","as","its","first","argument","(","all","others","left","at","default","values",")","and","vertices","are","filtered","according","to","the","value","returned","by","the","method",".","For","instance",",","if","you","want","to","exclude","isolated","vertices",":",">",">",">","g","=","Graph.Famous","(","``","zachary","''",")",">",">",">","non_isolated","=","g.vs.select","(","_degree_gt=0",")","For","properties","that","take","a","long","time","to","be","computed","(","e.g.",",","betweenness","centrality","for","large","graphs",")",",","it","is","advised","to","calculate","the","values","in","advance","and","store","it","in","a","graph","attribute",".","The","same","applies","when","you","are","selecting","based","on","the","same","property","more","than","once","in","the","same","C","{","select","(",")","}","call","to","avoid","calculating","it","twice","unnecessarily",".","For","instance",",","the","following","would","calculate","betweenness","centralities","twice",":",">",">",">","edges","=","g.vs.select","(","_betweenness_gt=10",",","_betweenness_lt=30",")","It","is","advised","to","use","this","instead",":",">",">",">","g.vs","[","``","bs","''","]","=","g.betweenness","(",")",">",">",">","edges","=","g.vs.select","(","bs_gt=10",",","bs_lt=30",")","@","return",":","the","new",",","filtered","vertex","sequence"]
code: def select(self, *args, **kwds):
      """Selects a subset of the vertex sequence based on some criteria
  
      The selection criteria can be specified by the positional and the keyword
      arguments. Positional arguments are always processed before keyword
      arguments.
  
        - If the first positional argument is C{None}, an empty sequence is
          returned.
  
        - If the first positional argument is a callable object, the object
          will be called for every vertex in the sequence. If it returns
          C{True}, the vertex will be included, otherwise it will
          be excluded.
  
        - If the first positional argument is an iterable, it must return
          integers and they will be considered as indices of the current
          vertex set (NOT the whole vertex set of the graph -- the
          difference matters when one filters a vertex set that has
          already been filtered by a previous invocation of
          L{VertexSeq.select()}. In this case, the indices do not refer
          directly to the vertices of the graph but to the elements of
          the filtered vertex sequence.
  
        - If the first positional argument is an integer, all remaining
          arguments are expected to be integers. They are considered as
          indices of the current vertex set again.
  
      Keyword arguments can be used to filter the vertices based on their
      attributes. The name of the keyword specifies the name of the attribute
      and the filtering operator, they should be concatenated by an
      underscore (C{_}) character. Attribute names can also contain
      underscores, but operator names don't, so the operator is always the
      largest trailing substring of the keyword name that does not contain
      an underscore. Possible operators are:
  
        - C{eq}: equal to
  
        - C{ne}: not equal to
  
        - C{lt}: less than
  
        - C{gt}: greater than
  
        - C{le}: less than or equal to
  
        - C{ge}: greater than or equal to
  
        - C{in}: checks if the value of an attribute is in a given list
  
        - C{notin}: checks if the value of an attribute is not in a given
          list
  
      For instance, if you want to filter vertices with a numeric C{age}
      property larger than 200, you have to write:
  
        >>> g.vs.select(age_gt=200)                   #doctest: +SKIP
  
      Similarly, to filter vertices whose C{type} is in a list of predefined
      types:
  
        >>> list_of_types = ["HR", "Finance", "Management"]
        >>> g.vs.select(type_in=list_of_types)        #doctest: +SKIP
  
      If the operator is omitted, it defaults to C{eq}. For instance, the
      following selector selects vertices whose C{cluster} property equals
      to 2:
  
        >>> g.vs.select(cluster=2)                    #doctest: +SKIP
  
      In the case of an unknown operator, it is assumed that the
      recognized operator is part of the attribute name and the actual
      operator is C{eq}.
  
      Attribute names inferred from keyword arguments are treated specially
      if they start with an underscore (C{_}). These are not real attributes
      but refer to specific properties of the vertices, e.g., its degree.
      The rule is as follows: if an attribute name starts with an underscore,
      the rest of the name is interpreted as a method of the L{Graph} object.
      This method is called with the vertex sequence as its first argument
      (all others left at default values) and vertices are filtered
      according to the value returned by the method. For instance, if you
      want to exclude isolated vertices:
  
        >>> g = Graph.Famous("zachary")
        >>> non_isolated = g.vs.select(_degree_gt=0)
  
      For properties that take a long time to be computed (e.g., betweenness
      centrality for large graphs), it is advised to calculate the values
      in advance and store it in a graph attribute. The same applies when
      you are selecting based on the same property more than once in the
      same C{select()} call to avoid calculating it twice unnecessarily.
      For instance, the following would calculate betweenness centralities
      twice:
  
        >>> edges = g.vs.select(_betweenness_gt=10, _betweenness_lt=30)
  
      It is advised to use this instead:
  
        >>> g.vs["bs"] = g.betweenness()
        >>> edges = g.vs.select(bs_gt=10, bs_lt=30)
  
      @return: the new, filtered vertex sequence"""
      vs = _VertexSeq.select(self, *args)
  
      operators = {
          "lt": operator.lt,
          "gt": operator.gt,
          "le": operator.le,
          "ge": operator.ge,
          "eq": operator.eq,
          "ne": operator.ne,
          "in": lambda a, b: a in b,
          "notin": lambda a, b: a not in b,
      }
      for keyword, value in kwds.items():
          if "_" not in keyword or keyword.rindex("_") == 0:
              keyword += "_eq"
          attr, _, op = keyword.rpartition("_")
          try:
              func = operators[op]
          except KeyError:
              # No such operator, assume that it's part of the attribute name
              attr, op, func = keyword, "eq", operators["eq"]
  
          if attr[0] == "_":
              # Method call, not an attribute
              values = getattr(vs.graph, attr[1:])(vs)
          else:
              values = vs[attr]
          filtered_idxs = [
              i for i, v in enumerate(values) if func(v, value)
          ]
          vs = vs.select(filtered_idxs)
  
      return vs
  
file_path: python-igraph/src/igraph/seq.py
imports: import operator
  from igraph._igraph import EdgeSeq, VertexSeq
label_desc: Use image node_id 3 for calling the VertexSeq obj's underlying member method code with example usage: obj.select() and returns: vs