Our Office
Ernakulam, Kottayam
Email Us
linusfacts@gmail.com
Call Us
+91 9544409513
1. Create a set that contains 5,1,3,7,8,2 and 3.<br>2. Print the set. Did it keep the order of the elements ?<br>3. Find the maximum and the minimum of the set.<br>4. Add the element of this list [False, 3.14, ‘Rose’] to the set.<br>5. Print the set. What is the order of the elements ?<br>6. Try to add another 1 to the set. Is it working ? Why ? 1. Create a dictionary named inventory with the following key-value pairs:<br>a. "apples" with a value of 10<br>b. "bananas" with a value of 12<br>c. "cherries" with a value of 34<br>2. Check if "bananas" is a key in the dictionary.<br>3. Check if 5 is a value in the dictionary.<br>4. Print the results.<br>5. Create a set named fruits with the items: "apples", "bananas" and "cherries"<br>6. Check if the number of items in the inventory dictionary is greater than the number of<br>items in the fruits set. 1. Create the following list : [('square', 'blue'), ('triangle', 'red'), ('circle', 'yellow')]<br>2. Transform this list into a dictionary.<br>Tips: Use the dict() function.<br>3. Add ‘rectangle’ to the dictionary with a value of ‘green’.<br>4. Remove the ‘circle’ key-value pair.<br>5. Remove the ‘triangle’ key-value pair using another method.<br>6. Find a way to turn the dictionary into a list of tuples again. 1. Create a set named fruits with the items: "apple", "banana", and "cherry".<br>2. Add "orange" to the set.<br>3. Check if "apple" is in the set and print the result. 1. Create a dictionary named person with the keys: "name", "age", and "job".<br>2. Assign appropriate values to each key.<br>3. Print the value associated with the key "name" from the dictionary. 1. Create a set named colors with the items: "red", "green", "blue".<br>2. Find one other way to create the set above.<br>3. Remove "green" from the set using the appropriate method.<br>4. Try removing "yellow" from the set using a method that won't raise an error if the item<br>doesn't exist.<br>5. Add ‘Purple’ and ‘Pink’ to the set in one operation.<br>6. Find the length of the set.<br>7. Empty the set.<br>8. Delete the set completely. 1. Given the dictionary prices with the following key-value pairs:<br>a. "apple" with a value of 0.5<br>b. "banana" with a value of 0.25<br>c. "orange" with a value of 0.75<br>2. Update the price of "banana" to 0.3.<br>3. Add “cherry” to the dictionary with a price of 0.1<br>4. Add “pear” to the dictionary with a price of 0.7 using another method.<br>5. Print the modified dictionary. 1. Create two sets: A = {1, 2, 3, 4} and B = {3, 4, 5, 6}.<br>2. If 5 is in set A, add it to set B. Otherwise, remove it from set B.<br>3. If 2 is not in set B, remove it from set A.<br>4. Print the resulting sets A and B.<br>5. Using a conditional structure, check if the sets have any elements in common.<br>a. If so, find the common elements.<br>b. If not, print a message. 1. Create a dictionary named employees where the keys are employee names and the<br>values are dictionaries containing keys "job_title" and "salary".<br>2. Add two employees to the employees dictionary with their respective job titles and<br>salaries.<br>3. Print the salary of the first employee you added. 1. Create a dictionary named car with keys: "brand", "model", “color” and "year" and<br>assign values to each.<br>2. Print all the keys of the dictionary using the appropriate dictionary method.<br>3. Print all the values of the dictionary using the appropriate dictionary method.

QUESTIONS

1. Create a set that contains 5,1,3,7,8,2 and 3.
2. Print the set. Did it keep the order of the elements ?
3. Find the maximum and the minimum of the set.
4. Add the element of this list [False, 3.14, ‘Rose’] to the set.
5. Print the set. What is the order of the elements ?
6. Try to add another 1 to the set. Is it working ? Why ?

Right Answer:


# Step 1
num_set = {5, 1, 3, 7, 8, 2, 3}
# Step 2
print(num_set) # Order is not preserved in sets
# Step 3
print("Max:", max(num_set)) # Max: 8
print("Min:", min(num_set)) # Min: 1
# Step 4
num_set.update([False, 3.14, "Rose"])
# Step 5
print(num_set) # Order is arbitrary in sets
# Step 6
num_set.add(1) # Adding a duplicate doesn't change the set

1. Create a dictionary named inventory with the following key-value pairs:
a. "apples" with a value of 10
b. "bananas" with a value of 12
c. "cherries" with a value of 34
2. Check if "bananas" is a key in the dictionary.
3. Check if 5 is a value in the dictionary.
4. Print the results.
5. Create a set named fruits with the items: "apples", "bananas" and "cherries"
6. Check if the number of items in the inventory dictionary is greater than the number of
items in the fruits set.

Right Answer:


# Step 1
inventory = {
"apples": 10,
"bananas": 12,
"cherries": 34
}
# Step 2
print("bananas" in inventory) # Output: True
# Step 3
print(5 in inventory.values()) # Output: False
# Step 4
fruits = {"apples", "bananas", "cherries"}
# Step 5 & 6
if len(inventory) > len(fruits):
print("Inventory has more items.")
else:
print("Fruits set has equal or more items.")

1. Create the following list : [('square', 'blue'), ('triangle', 'red'), ('circle', 'yellow')]
2. Transform this list into a dictionary.
Tips: Use the dict() function.
3. Add ‘rectangle’ to the dictionary with a value of ‘green’.
4. Remove the ‘circle’ key-value pair.
5. Remove the ‘triangle’ key-value pair using another method.
6. Find a way to turn the dictionary into a list of tuples again.

Right Answer:


# Step 1
shapes = [('square', 'blue'), ('triangle', 'red'), ('circle', 'yellow')]
# Step 2
shapes_dict = dict(shapes)
# Step 3
shapes_dict['rectangle'] = 'green'
# Step 4
shapes_dict.pop('circle')
# Step 5
del shapes_dict['triangle']
# Step 6
shapes_list = list(shapes_dict.items())
print(shapes_list)
# Output: [('square', 'blue'), ('rectangle', 'green')]

1. Create a set named fruits with the items: "apple", "banana", and "cherry".
2. Add "orange" to the set.
3. Check if "apple" is in the set and print the result.

Right Answer:


# Step 1
fruits = {"apple", "banana", "cherry"}
# Step 2
fruits.add("orange")
# Step 3
print("apple" in fruits) # Output: True

1. Create a dictionary named person with the keys: "name", "age", and "job".
2. Assign appropriate values to each key.
3. Print the value associated with the key "name" from the dictionary.

Right Answer:


# Step 1
person = {
"name": "John Doe",
"age": 30,
"job": "Engineer"
}
# Step 3
print(person["name"]) # Output: John Doe

1. Create a set named colors with the items: "red", "green", "blue".
2. Find one other way to create the set above.
3. Remove "green" from the set using the appropriate method.
4. Try removing "yellow" from the set using a method that won't raise an error if the item
doesn't exist.
5. Add ‘Purple’ and ‘Pink’ to the set in one operation.
6. Find the length of the set.
7. Empty the set.
8. Delete the set completely.

Right Answer:


# Step 1
colors = {"red", "green", "blue"}
# Step 2
colors_alternate = set(["red", "green", "blue"])
# Step 3
colors.discard("green")
# Step 4
colors.discard("yellow") # No error raised if "yellow" doesn't exist
# Step 5
colors.update(["Purple", "Pink"])
# Step 6
print(len(colors))
# Step 7
colors.clear()
# Step 8
del colors

1. Given the dictionary prices with the following key-value pairs:
a. "apple" with a value of 0.5
b. "banana" with a value of 0.25
c. "orange" with a value of 0.75
2. Update the price of "banana" to 0.3.
3. Add “cherry” to the dictionary with a price of 0.1
4. Add “pear” to the dictionary with a price of 0.7 using another method.
5. Print the modified dictionary.

Right Answer:


# Step 1
prices = {
"apple": 0.5,
"banana": 0.25,
"orange": 0.75
}
# Step 2
prices["banana"] = 0.3
# Step 3
prices["cherry"] = 0.1
# Step 4
prices.update({"pear": 0.7})
# Step 5
print(prices)
# Output: {'apple': 0.5, 'banana': 0.3, 'orange': 0.75, 'cherry': 0.1, 'pear': 0.7}

1. Create two sets: A = {1, 2, 3, 4} and B = {3, 4, 5, 6}.
2. If 5 is in set A, add it to set B. Otherwise, remove it from set B.
3. If 2 is not in set B, remove it from set A.
4. Print the resulting sets A and B.
5. Using a conditional structure, check if the sets have any elements in common.
a. If so, find the common elements.
b. If not, print a message.

Right Answer:


# Step 1
A = {1, 2, 3, 4}
B = {3, 4, 5, 6}
# Step 2
if 5 in A:
B.add(5)
else:
B.discard(5)
# Step 3
if 2 not in B:
A.discard(2)
# Step 4
print("A:", A)
print("B:", B)
# Step 5
if A & B:
print("Common elements:", A & B)
else:
print("No common elements.")

1. Create a dictionary named employees where the keys are employee names and the
values are dictionaries containing keys "job_title" and "salary".
2. Add two employees to the employees dictionary with their respective job titles and
salaries.
3. Print the salary of the first employee you added.

Right Answer:


# Step 1
employees = {
"Akash": {"job_title": "Engineer", "salary": 50000},
"Dev": {"job_title": "Manager", "salary": 60000}
}
# Step 2 & 3
print(employees["Dev"]["salary"]) # Output: 50000

1. Create a dictionary named car with keys: "brand", "model", “color” and "year" and
assign values to each.
2. Print all the keys of the dictionary using the appropriate dictionary method.
3. Print all the values of the dictionary using the appropriate dictionary method.

Right Answer:


# Step 1
car = {
"brand": "Toyota",
"model": "Corolla",
"color": "Blue",
"year": 2020
}
# Step 2
print(car.keys()) # Output: dict_keys(['brand', 'model', 'color', 'year'])
# Step 3
print(car.values()) # Output: dict_values(['Toyota', 'Corolla', 'Blue', 2020])

Get In Touch

Kochi, Pala,Ernakulam

+91 9544409513

linuslearning.in@gmail.com

Our Courses
Newsletter

Those people who develop the ability to continuously acquire new and better forms of knowledge that they can apply to their work and to their lives will be the movers and shakers in our society for the indefinite future