I am doing a problem, the input is strings:
["abc","bcd","acef","xyz","az","ba","a","z"]
The code is listed below.
def groupStrings(self, strings):
groups = collections.defaultdict(list)
for s in strings:
tmp=[0]*len(s)
for i in range(len(s)):
tmp[i]=(ord(s[i])-ord(s[0]))%26
tmptuple=tuple(tmp)
groups[tmptuple] += s,
return groups.values()
So in groups[tmptuple]+=s,
if I remove the comma ',' I get
[["a","b","c","b","c","d","x","y","z"],["a","c","e","f"],["a","z"],["a","z","b","a"]]
instead of
[["abc","bcd","xyz"],["acef"],["a","z"],["az","ba"]]
The groups just does not add the whole string s, can anyone explain why does the comma make it different and why I could not do it without the comma?