Answer to Question #312080 in Python for Govind

Question #312080

Akshay is given a list of n integers. Each number in the list appears exactly twice except one number.help Akshay by identifying the number which appeared once in the list.

1
Expert's answer
2022-03-15T12:12:13-0400
def singl_number(L):
    D = {}
    for x in L:
        D[x] = D.get(x, 0) + 1
    
    for x in D:
        if D[x] == 1:
            return x

def main():
    L = [1, 2, 2, 3, 1]
    x = singl_number(L)
    print(f'The number {x} appears once in the list {L}')

main()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS