Skip to content

Instantly share code, notes, and snippets.

@arjunv
Created April 3, 2018 16:56
Show Gist options
  • Save arjunv/fa2c54148b4a65f702d8e5f223e84aad to your computer and use it in GitHub Desktop.
Save arjunv/fa2c54148b4a65f702d8e5f223e84aad to your computer and use it in GitHub Desktop.
how is this working?
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)
@arjunv
Copy link
Author

arjunv commented Apr 3, 2018

Am I not modifying a variable 'test' outside the global scope?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment