<jupyter_start><jupyter_text>Python Dictionaries<jupyter_code>mydict = {"myname":"Valdis","food":"potatoes","height":180, "numbers":[1,2,3,6]}
print(mydict)
mydict["food"]
mydict['food']
mydict['height']
mydict['numbers']
type(mydict['numbers'])
type(mydict)
mydict
mydict['height'] = 185
mydict
mydict['weight'] = 85
mydict
# we just added a new key -> value pair
'weight' in mydict
mydict.items()
len(mydict)
mykeys = mydict.keys()
mykeys = mydict.keys()
type(mykeys)
print(mykeys)
mykeylist = list(mykeys)
mykeylist
myvalues = mydict.values()
myvalues
myvaluelist = list(myvalues)
myvaluelist
mydict.update({'food':'bread', 'jump': 200})
mydict
del mydict['weight']
del mydict['weight']
mydict.pop('weight')
mydict.clear()
len(mydict)
mydict
newdict = {}
newdict['myname'] = 'Valdis'
newdict
mydict
myfood = mydict.pop('food')
mydict
myfood
# Iterating over a dictionary keys AND values
for key, value in mydict.items():
    print(key,value)
    # do something with each key and/or value
print(key,value)
mydict.clear()
mydict
mydict = {"myname":"Valdis","food":"potatoes","height":180, "numbers":[1,2,3,6]}
mydict['myname']
mykey = 'myname'
mydict[mykey]
mykey in mydict
for key in mydict.keys():
    print("Current key is", key)
    # print the value of current key
    print("Current value is", mydict[key])
    
print("Last value of last item is", mydict[key][-1])
mylist = [x*x for x in range(1,11)]
mylist
#Dictionary comprehension
mysquares = { "MySecretKey"+str(x) : x*x for x in range(1,11)}
print(mysquares)
mysq2 = {}
for x in range(1,11):
    print("Working on key number", x)
    mysq2["Key"+str(x)]=x*x

print(mysq2)
mycubes = {}
for x in range(1,16):
    mycubes[x]=x*x*x

# maybe a dictionary comprehension above
# maybe a regular loop below
print(mycubes)
sum(mycubes.values())
result = 0
for x in mycubes.values():
    # Do nothing
    result += x
    print("Starp vertibas",result)
    # we can more more stuff with individual x or just do other stuff

print("Final result", result)
type(mycubes)
len(mycubes.keys()), mycubes.keys()
mycubes[16]
mycubes[16]
mycubes.get(16, 42)
mycubes.get(15, 42)
mycubes.setdefault(15, 4000)
mycubes.setdefault(16, 4000)
mycubes.get(16)
16 in mycubes
17 in mycubes
16 in mycubes.keys()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1567591369440775, 'fraction_numerical': 0.03126376045794804, 'mean_word_length': 5.761904761904762, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 6, '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}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '99992', 'license': 'MIT', 'n_tokens_mistral': 926, 'n_tokens_neox': 859, 'n_words': 223, 'path': '.ipynb_checkpoints/Python Dictionaries_in_class-checkpoint.ipynb', 'repo_name': 'ValRCS/RCS_Data_Analysis_Python_2019', 'size': '2271'}