Created
April 3, 2018 16:56
-
-
Save arjunv/fa2c54148b4a65f702d8e5f223e84aad to your computer and use it in GitHub Desktop.
how is this working?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if args.random: | |
def get_data_structures(): | |
# while sets do not preserve the order of insertion, they are are much faster | |
return set() | |
def add_entries(data_set,data): | |
# adding addresses to a set which prevents duplicate entries, but does not preserve order | |
data_set.add(data) | |
else: | |
def get_data_structures(): | |
# from python3.6, dictionaries preserve the order of insertion | |
return {} | |
def add_entries(data_set,data): | |
# adding items as keys to a dictionary which prevents duplicate entries and preserves order | |
data_set.__setitem__(data, True) | |
test = get_data_structures() | |
with open(test_file, 'r') as f: | |
[add_entries(test, line.strip()) for line in f] | |
print(test) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Am I not modifying a variable 'test' outside the global scope?