How to Find the Only Odd Number of Element in Python


This example will teach us how to find the only odd number of elements in a group.

Source Code

#! /usr/bin/env python3
# -*- coding: utf-8 -*-

nlist = input("Please input a list separated by SPACE: ").split()
nlist = [int(i) for i in nlist]
odd = 0
for i in nlist:
    odd ^= i
print(odd)

Output:

Please input a list separated by SPACE: 5 8 10 12 10 8 5 9 12
9
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments