<jupyter_start><jupyter_text>How do we access data?Instead of 0,1,2,3... indexes we need to use keys here in dictionaries<jupyter_code>a['list']
a["dict"]
a["dict"]
a.get(1)
a[1]
a.get('list')
a.get("li")       # I don't get an error and didn't print anything
print(a.get("li"))  # By default it returned None
print(a["li"])      # Here it's throwing an error<jupyter_output><empty_output><jupyter_text>Difference between [ ] and get() in dictionaries?<jupyter_code>a.get('li', 0)       # It will return the value associated with key if key is present
                     # otherwise the second argument is returned
a.keys()             # To get all keys of a dictionary
a.values()           # To get all values of a dictionary 
a.items()            # To get all key-value pairs of a dictionary
# How can we use a for loop for a dictionary?
for i in a:
    print(i)           # gets all the keys one by one
for i in a: 
    print(a[i])        #gets all the values one by one 
for i in a:    
    print(i, a[i])     # gets all the key - value pairs
for i in a.values():   # Accessing only values of a dictionary  
    print(i)          
# Check if a key exists in a dictionary or not?

"list" in a     # This is not for value it's only for key
"li" in a
2 in a         # Here 2 is a value not a key so it returned False<jupyter_output><empty_output><jupyter_text>Dictionaries are pretty fast and you can use it in many problems like counting the frequency and so on and so forth<jupyter_code># Predict the Output:
d = {1:2, "abc":5, "def":7}
print(d[0])
# Predict the Output:
d = {1:2, "abc":5, "def":7}
print(d.get(0,5))
# Predict the Output:
d = {1:2, "abc":5, "def":7}   
if 2 in d:                   # Here it checks only for key not the value. So, it returned False
    print('Present')
else:
    print('Not Present')<jupyter_output>Not Present
{'fraction_non_alphanumeric': 0.11032990805840995, 'fraction_numerical': 0.01352082206598161, 'mean_word_length': 2.961456102783726, 'pattern_counts': {'":': 6, '<': 12, '<?xml version=': 0, '>': 12, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '74809', 'license': 'Unlicense', 'n_tokens_mistral': 623, 'n_tokens_neox': 603, 'n_words': 255, 'path': '18 Dictionaries/18.02 Accessing  or Looping elements in dictionaries.ipynb', 'repo_name': 'suhassuhas/Coding-Ninjas---Data-Structures-and-Algorithms-in-Python', 'size': '1849'}