にしお #3663(2007/11/02 10:40 GMT) [ Python ] Rating0/0=0.00
なぜ4人とも結果が違うのかがむしろ新たな問題になっちゃうかも(笑 ソースコードは公開されていますし。 とりあえず僕のコードも公開することにします。 変数dataにユニコード文字列のリストが入っています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
starts = set(w[0] for w in data) ends = set(w[3] for w in data) from collections import defaultdict start_dict = defaultdict(list) end_dict = defaultdict(list) for w in data: start_dict[w[0]].append(w) end_dict[w[3]].append(w) count = 0 for s in start_dict: starts = start_dict[s] n = len(starts) if n < 2: continue for e in end_dict: ends = end_dict[e] if len(ends) < 2: continue heads = [w[0] for w in ends] for i in range(n): w = starts[i] tail = w[3] if tail not in heads: continue for j in range(i + 1, n): w2 = starts[j] tail2 = w2[3] if tail == tail2: continue if tail2 in heads: w3 = ends[heads.index(tail)] w4 = ends[heads.index(tail2)] count += 1 print w print u"%s %s" % (w2[1], w3[1]) print u"%s %s" % (w2[2], w3[2]) print w4 print
Rating0/0=0.00-0+
1 reply [ reply ]
にしお
#3663()
[
Python
]
Rating0/0=0.00
Rating0/0=0.00-0+