Skip to content

Instantly share code, notes, and snippets.

@FBosler
Created August 20, 2020 16:47
Show Gist options
  • Save FBosler/17f8da71e8c423e82e2b5c49afd4abd1 to your computer and use it in GitHub Desktop.
Save FBosler/17f8da71e8c423e82e2b5c49afd4abd1 to your computer and use it in GitHub Desktop.
import uuid
import random
import string
# GENERATE SAMPLE DATA
sample_data = [{
'_id': uuid.uuid4().hex,
'name': ''.join(random.choices(
[_ for _ in string.ascii_letters],
k=10
)),
'net_worth': random.randint(10,100)*1000
} for i in range(1000)]
random_entry = random.choice(sample_data)
print(random_entry)
# BUILD THE HASH_TABLE
hash_table = {
_['_id']:_
for _ in sample_data
}
# CHANGE ENTRY VIA '_id'
hash_table[random_entry['_id']]['net_worth'] = 10000
print(random_entry)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment