Split lists and tuples in Python
问题 I have a simple question. I have list, or a tuple, and I want to split it into many lists (or tuples) that contain the same elements. I'll try to be more clear using an example: (1,1,2,2,3,3,4) --> (1,1),(2,2),(3,3),(4,) (1,2,3,3,3,3) --> (1,),(2,),(3,3,3,3) [2,2,3,3,2,3] --> [2,2],[3,3],[2],[3] How can I do? I know that tuples and lists do not have the attribute "split" so i thought that i could turn them into strings before. This is what i tried: def splitt(l) x=str(l) for i in range (len(x