fork download
  1. class Foo():
  2. def __init__(self, key, value):
  3. self.key = key
  4. self.value = value
  5.  
  6. def main():
  7. foo = [Foo(2, 1), Foo(1, 2), Foo(5, 3)]
  8. range1 = [ x for x in foo if x.key == 1 ]
  9. print("value for key 1 is", range1[0].value)
  10.  
  11. main()
Success #stdin #stdout 0.1s 10104KB
stdin
Standard input is empty
stdout
value for key 1 is 2