How to get the Items between two certain Symbols in a List

Solution 1:

One possible approach would be to find the indices of the special character, and split the list into chunks between the first and last occurrence:

indices = [i for i, v in enumerate(dataList) if v == "•"]
result = [dataList[indices[i - 1] + 1:indices[i]] for i in range(1, len(indices))]

For your input, you get

>>> result
[['tv', 'tv'], ['tv'], ['tv', 'tv']]

Now you can print and do other things with that value. For example:

>>> for s in result:
...     print(*s, sep=', ')
tv, tv
tv
tv, tv

It's always better to compute intermediate results than just print them if you plan to reuse them for something else.

Solution 2:

dataList = ["tv", "•", "tv", "tv", "•", "tv", "•", "tv", "tv", "•"]
searchFor = "•"
allVals = []
isFound = False
oldIdx = -1
for idx, item in enumerate(dataList):
    if item == searchFor:
        if isFound:
            # loop complete
            allVals.append(dataList[oldIdx + 1 : idx ])
            isFound = False
        else:
            isFound = True
            oldIdx = idx

allVals
[['tv', 'tv'], ['tv', 'tv']]
allStrings = [",".join(x) for x in allVals]

allStrings
['tv,tv', 'tv,tv']