E-mail : support@tech2now.in

Find the number occurrence in the list in Python

See the example below to find the number that appears once in the list.

def singleTimeAppaer(list):
    response = []
    for i in list:
        appearance = 0
        for k in list:
            if k == i:
                appearance = appearance+1
                if appearance > 1:
                    response.append(i)

    set_dif = set(list).symmetric_difference(set(response))
    return set_dif


if __name__ == '__main__':
    lst = [1, 2, 3, 4, 111, 12, 33, 44, 55, 66,
           77, 1, 12, 33, 44, 55, 66, 77, 2, 3, 4, 222]
    print(f'Elements those appear only once in list {singleTimeAppaer(lst)}')

Output:

Elements those appear only once in list {111, 222}

GitHub Repository URL