<commit_before>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

def lonely_integer():
	pass


def main():
	pass


if __name__ == '__main__':
	main()<commit_msg>Complete lonely int by naive dict & bit op<commit_after>from __future__ import absolute_import
from __future__ import division
from __future__ import print_function


def lonely_integer_naive(a_list):
    """Lonely integer by naive dictionary.

    Time complexity: O(n).
    Space complexity: O(n).
    """
    integer_count_d = {}
    
    for x in a_list:
        if x in integer_count_d:
            integer_count_d[x] += 1
        else:
            integer_count_d[x] = 1

    for integer, count in integer_count_d.items():
        if count == 1:
            return integer


def lonely_integer(a_list):
    """Lonely integer by bit operation.

    Time complexity: O(n).
    Space complexity: O(1).
    """
    integer = 0
    for x in a_list:
        integer ^= x
    return integer


def main():
    import time

    a_list = [9, 1, 2, 3, 2, 9, 1, 7, 7]
 
    start_time = time.time()
    print('Find lonely integer by naive dictionary: {}'
          .format(lonely_integer_naive(a_list)))
    print('Time: {}'.format(time.time() - start_time))

    start_time = time.time()
    print('Find lonely integer by bit operation: {}'
          .format(lonely_integer(a_list)))
    print('Time: {}'.format(time.time() - start_time))


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.10843373493975904, 'fraction_numerical': 0.009370816599732263, 'mean_word_length': 2.873056994818653, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6775060', 'n_tokens_mistral': 498, 'n_tokens_neox': 469, 'n_words': 142}