fork download
  1. items = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'tree']
  2.  
  3. count = 4
  4. mustContain = ["e", "i"] # all of these characters at least once
  5. mustNotContain = ["n", "o"] # none of those chars
  6.  
  7. hits = [
  8. item for item in items if
  9. len(item) == count and
  10. all([c in item for c in mustContain]) and
  11. all([c not in item for c in mustNotContain])
  12. ]
  13. print(hits)
Success #stdin #stdout 0.03s 9072KB
stdin
Standard input is empty
stdout
['five']