i have list of string.
a = [ 'kite1.json', 'kite1.mapping.json', 'kite1.analyzer.json', 'kite2.json', 'kite3.mapping.json', 'kite3.mapping.mapping.json', 'kite3.mapping.analyzer.json', ] i need find common prefix ends of .json, .mapping.json, .analyzer.json.
here, kite1 & kite3.mapping satisfied. kite2 isn't, because ends .json.
how can find prefix ends of .json, .mapping.json, .analyzer.json.
if code-golf, might win:
def ew(sx): return set([s[:-len(sx)] s in if s.endswith(sx)]) ew('.analyzer.json') & ew('.mapping.json') & ew('.json') the ew() function loops through a, finding elements end given suffix , stripping suffix off, returning results @ set.
using it, calculate intersection of sets produced each of 3 suffixes. (& operator intersection.)
for brevity's sake, abbreviated "ends with" ew , "suffix" sx.
the expression s[:-len(sx)] means "the substring of s starting @ 0 , going len(sx) characters end", has effect of snipping suffix off end.