<jupyter_start><jupyter_text>Questions 1. Write a Python program to Extract Unique values dictionary values?2. Write a Python program to find the sum of all items in a dictionary?3. Write a Python program to Merging two Dictionaries?4. Write a Python program to convert key-values list to flat dictionary?5. Write a Python program to insertion at the beginning in OrderedDict?6. Write a Python program to check order of character in string using OrderedDict()?7. Write a Python program to sort Python Dictionaries by Key or Value?  Answers  1 :<jupyter_code>dic = {'a' : [4, 8, 7, 9],'b' : [12, 11, 7, 4],'c' : [11, 12, 10, 9]}

val  = []
for i in dic.values():
    val += i
    
unique_val = list(set(val))
print(unique_val)<jupyter_output>[4, 7, 8, 9, 10, 11, 12]<jupyter_text>2 :<jupyter_code>dic = {'a' : [4, 8, 7, 9],'b' : [12, 11, 7, 4],'c' : [11, 12, 10, 9]}

sum_ = sum([sum(i) for i in dic.values()])

print(sum_)<jupyter_output>104<jupyter_text>3 :<jupyter_code>dic1 = {'a' : [4, 8, 7, 9],'b' : [12, 11, 7, 4],'c' : [11, 12, 10, 9]}
dic2 = {'a' : [4, 8, 7, 9],'b' : [12, 11, 7, 4],'c' : [11, 12, 10, 9],'d':[4,8,45,9]}

comb_dic = {**dic1,**dic2}
comb_dic<jupyter_output><empty_output><jupyter_text>4 :<jupyter_code>dic = {"Name":["Sachin","Sania","Bhutia"],"sports":["Cricket","Tenis","Football"]}

flat_dic = {k:v for k,v in zip(dic["Name"],dic["sports"])}
flat_dic<jupyter_output><empty_output><jupyter_text>5 :<jupyter_code>from collections import OrderedDict
order_dic = OrderedDict({'Sachin': 'Cricket', 'Sania': 'Tenis', 'Bhutia': 'Football'})
order_dic
order_dic.update({"Gagan":"Shooting"})
order_dic.move_to_end('Gagan', last = False)
order_dic<jupyter_output><empty_output><jupyter_text>6 :<jupyter_code>from collections import OrderedDict 
  
def check_order(st, pattern): 
      
    dic = OrderedDict.fromkeys(st) 

    p_len = 0
    for key,value in dic.items(): 
        if key == pattern[p_len]: 
            p_len = p_len + 1
          
        if p_len == (len(pattern)): 
            return True
  
    return False
st = "python program"
pattern = "th"
check_order(st,pattern)
st = "python program"
pattern = "yth"
check_order(st,pattern)
st = "python program"
pattern = "op"
check_order(st,pattern)<jupyter_output><empty_output><jupyter_text>7 :<jupyter_code>x = {"e": 20, "b": 4, "c": 30, "a": 25, "d": 34}

sort_keys = {k: v for k, v in sorted(x.items(), key=lambda item: item[0])}
sort_values = {k: v for k, v in sorted(x.items(), key=lambda item: item[1])}

print(sort_keys)
print(sort_values)<jupyter_output>{'a': 25, 'b': 4, 'c': 30, 'd': 34, 'e': 20}
{'b': 4, 'e': 20, 'a': 25, 'c': 30, 'd': 34}
{'fraction_non_alphanumeric': 0.18344094189137866, 'fraction_numerical': 0.051272312951006455, 'mean_word_length': 4.8017621145374445, 'pattern_counts': {'":': 8, '<': 26, '<?xml version=': 0, '>': 26, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '84919', 'license': 'MIT', 'n_tokens_mistral': 1193, 'n_tokens_neox': 1071, 'n_words': 291, 'path': 'Python Programming Basic Assignment/Assignment_12.ipynb', 'repo_name': 'kpsanjeet/Python-Programming-Basic-Assignment', 'size': '2633'}