Robert R. schrieb: > Hello, > > i would like to write a piece of code to help me to align some sequence > of words and suggest me the ordered common subwords of them > > s0 = "this is an example of a thing i would like to have".split() > s1 = "another example of something else i would like to have".split() > s2 = 'and this is another " example " but of something ; now i would > still like to have'.split() > ... > alist = (s0, s1, s2) > > result should be : ('example', 'of', 'i', 'would', 'like', 'to', 'have' > > but i do not know how should i start, may be have you a helpful > suggestion? > a trouble i have if when having many different strings my results tend > to be nothing while i still would like to have one of the, or maybe, > all the best matches. > > best. >
As far as I can see, you want to have the words, that all three lists have in common, right? s0 = "this is an example of a thing i would like to have".split() s1 = "another example of something else i would like to have".split() s2 = 'and this is another " example " but of something ; now i would still like to have'.split() def findCommons(s0, s1, s2): res = [] for word in s0: if word in s1 and word in s2: res.append(word) return res >>>print findCommons(s0,s1,s2) ['example', 'of', 'i', 'would', 'like', 'to', 'have'] -- http://mail.python.org/mailman/listinfo/python-list