<jupyter_start><jupyter_text>A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values.<jupyter_code># creating a dictionary

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
print(thisdict)
thisdict["brand"] = 'Maruti'
thisdict['brand']
# accessing values

x = thisdict["model"]
x
# using the get() function

x = thisdict.get("model")
x
# updating the values

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict["year"] = 2018

thisdict
# accessing the keys

for x in thisdict:
    print(x)
# accessing the values

for x in thisdict:
    print(thisdict[x])
# using the values() to access the values in a dict

for x in thisdict.values():
    print(x)
# accessing both the key and values

for x, y in thisdict.items():
    print(x, y)
# checking if that particular string exists or not

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
if "model" in thisdict:
    print("Yes, 'model' is one of the keys in the thisdict dictionary")
# adding items to the list

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict["color"] = "red"
thisdict["color"] = "blue"
thisdict["colors"] = "red"
print(thisdict)

# removing the items from the dict

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict.pop("year")
print(thisdict)

# removing the last item from the dict

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict.popitem()
print(thisdict)
# using del keyword to remove the elements

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
del thisdict["model"]
print(thisdict)
# deleting the dictionary

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
del thisdict

# emptieing the dictionary

thisdict = {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict.clear()
print(thisdict)

# nested dictionary

child1 = {
  "name" : "Emil",
  "year" : 2004
}
child2 = {
  "name" : "Tobias",
  "year" : 2007
}
child3 = {
  "name" : "Linus",
  "year" : 2011
}
child4 = {
  "name" : "Linus",
  "year" : 2011
}

myfamily = {
  "child1" : child1,
  "child2" : child2,
  "child3" : child3
}
myfamily2 = {
    "child4":child4,
}

family = {
    "myfamily":myfamily,
    "myfamily2":myfamily2,
}

family
# one dictionary containing multiple dictionaries

myfamily = {
  "child1" : {
    "name" : "Emil",
    "year" : 2004
  },
  "child2" : {
    "name" : "Tobias",
    "year" : 2007
  },
  "child3" : {
    "name" : "Linus",
    "year" : 2011
  }
}

myfamily
# creating a dictionary using the dict keyword

thisdict = dict(brand="Ford", model="Mustang", year=1964)

print(thisdict)<jupyter_output>{'brand': 'Ford', 'model': 'Mustang', 'year': 1964}<jupyter_text>Dictionary Methods * clear()	Removes all the elements from the dictionary* copy()	Returns a copy of the dictionary* fromkeys()	Returns a dictionary with the specified keys and values* get()	Returns the value of the specified key* items()	Returns a list containing the a tuple for each key value pair* keys()	Returns a list containing the dictionary's keys* pop()	Removes the element with the specified key* popitem()	Removes the last inserted key-value pair* setdefault()	Returns the value of the specified key. If the key does not exist: insert the key, with the specified value* update()	Updates the dictionary with the specified key-value pairs* values()	Returns a list of all the values in the dictionary<jupyter_code>## Q9. Take a Number and check whether a number is Prime or not
def primenumber(x):
    if x>1:
        for i in range(2,x//2):
            if(x%i==0):
                print("number is not prime")
                break
            else:
                print("number is prime no")
    else:
        print('ff')
primenumber(7)
# Program to display the Fibonacci sequence up to n-th term

nterms = int(input("How many terms? "))

# first two terms
n1, n2 = 0, 1
count = 0

# check if the number of terms is valid
if nterms <= 0:
   print("Please enter a positive integer")
elif nterms == 1:
   print("Fibonacci sequence upto",nterms,":")
   print(n1)
else:
   print("Fibonacci sequence:")
   while count < nterms:
       print(n1)
       nth = n1 + n2
       # update values
       n1 = n2
       n2 = nth
       count += 1
string = "$ 50 M"
x = string.split()
int(x[1])
string = "$ 50 M"
string.split(' ')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13725055432372504, 'fraction_numerical': 0.026607538802660754, 'mean_word_length': 3.5427995971802617, 'pattern_counts': {'":': 31, '<': 10, '<?xml version=': 0, '>': 9, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '347225', 'license': 'Apache-2.0', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1541, 'n_words': 524, 'path': '08. Dictionary.ipynb', 'repo_name': 'coderscluster/Python_Basics', 'size': '4510'}