In the following piece of code I'm only printing out the sequence of elements in list that are increasing by 1
for example from this list
[88, 44, 4, 5, 6, 7, 18]
I want to print this
"4, 5, 6, 7" (converted to string)
I've managed to do the main part, but the output is [4, 5, 6, 7] instead of "4, 5, 6, 7"
def __str__(self):
for x, y in itertools.groupby(enumerate(self.lst), lambda z: z[0] - z[1]):
elements = [i[1] for i in y]
if len(elements) > 1:
return str("".join(str(elements)))
I hope this piece is enough. The entire code was just too big