fork download
  1. import json
  2. import sys
  3.  
  4. myList = json.load(sys.stdin)
  5.  
  6. def foo(myList,key,first=True):
  7. return [x for x in myList if key in x or not first and key in x[1]]
  8.  
  9.  
  10. print("foo:")
  11. print(foo(myList, 'abc', first=True))
  12. print(foo(myList, 'abc', first=False))
  13.  
  14. print("if any():")
  15. print([lst for lst in myList if any('abc' in s for s in lst)])
  16. print([lst for lst in myList if 'abc' in lst[0]])
  17.  
  18.  
  19.  
Success #stdin #stdout 0.04s 6732KB
stdin
[["abc-1", "def"]]
stdout
foo:
[]
[]
if any():
[[u'abc-1', u'def']]
[[u'abc-1', u'def']]