日期:2014-05-18 浏览次数:20704 次
#!/usr/bin/python # encoding: utf-8 rul = "125,241,250,320,440,330,120,880,990,230,770,883" def ln2ls(ln): return map(int, ln.strip().split(',')) rul = ln2ls(rul) lns = '''111,222,247,313,444,320,123,888,999,235,777,888 121,252,257,323,454,330,123,888,999,235,777,888 131,262,267,333,464,340,123,888,999,235,777,888 141,272,277,343,474,350,123,888,999,235,777,888''' rs = [] for ln in lns.splitlines(): ls = ln2ls(ln) rs.append([i for i, r in zip(ls, rul) if -15 <= i-r <= 15][:4]) for r in rs: print r #~ >python -u "test.py" #~ [111, 247, 313, 444] #~ [121, 252, 257, 323] #~ [131, 333, 340, 123] #~ [123, 888, 999, 235] #~ >Exit code: 0 Time: 0.075