fork(6) download
  1. import itertools
  2. from pprint import pprint
  3.  
  4. go_to_one_of = ['Finger Lakes', 'Central NY']
  5.  
  6. events = [
  7. ('Pittsburgh', 2),
  8. ('Miami Valley', 2),
  9. ('Tech Valley', 2),
  10. ('Central NY', 3),
  11. ('Finger Lakes', 3),
  12. ('Hudson Valley', 4),
  13. ('Long Island 1', 4),
  14. ('NYC', 6),
  15. ('Long Island 2', 6),
  16.  
  17. ('Buckeye?', 5),
  18. ]
  19.  
  20.  
  21. def conditions(combination):
  22. back_to_back = abs(combination[0][1] - combination[1][1]) == 1
  23.  
  24. attending_close = combination[0][0] in go_to_one_of or combination[1][0] in go_to_one_of
  25.  
  26. return (not back_to_back) and attending_close and combination[0][1] != combination[1][1]
  27.  
  28. pprint(
  29. list(
  30. filter(
  31. lambda comb: conditions(comb),
  32. itertools.combinations(events, 2)
  33. )
  34. )
  35. )
  36.  
Success #stdin #stdout 0.04s 9556KB
stdin
Standard input is empty
stdout
[(('Central NY', 3), ('NYC', 6)),
 (('Central NY', 3), ('Long Island 2', 6)),
 (('Central NY', 3), ('Buckeye?', 5)),
 (('Finger Lakes', 3), ('NYC', 6)),
 (('Finger Lakes', 3), ('Long Island 2', 6)),
 (('Finger Lakes', 3), ('Buckeye?', 5))]