<jupyter_start><jupyter_text>Practice Exercise - 04 - Solution  Question 1:We have two sets given below. Print the set of elements that are present in either set1 or set2 but not both.set1 = {1, 2, 3, 4, 5}set2 = {4, 5, 6, 7} Expected Output:{1, 2, 3, 6, 7}<jupyter_code>set1 = {1, 2, 3, 4, 5}
set2 = {4, 5, 6, 7}

set1 ^ set2<jupyter_output><empty_output><jupyter_text>Question 2:Print all the keys of the dictionary given below.myDict = {1:'One', 2:'Two', 3:'Three'} Expected Output:dict_keys([1, 2, 3])<jupyter_code>myDict = {1:'One', 2:'Two', 3:'Three'}

myDict.keys()<jupyter_output><empty_output><jupyter_text>Question 3:We have two sets given below. Print the elements common to both the sets.set1 = {1, 2, 3, 4, 5}set2 = {4, 5, 6, 7} Expected Output:{4, 5}<jupyter_code>set1 = {1, 2, 3, 4, 5}
set2 = {4, 5, 6, 7}

set1 & set2<jupyter_output><empty_output><jupyter_text>Question 4:We have a dictionary given below. Delete the item with key '3,' and add an item with key '7' and value 'Black.'color = {1:'Red', 2:'Orange', 3:'White', 4:'Brown', 5:'Yellow'} Expected Output:{1: 'Red', 2: 'Orange', 4: 'Brown', 5: 'Yellow', 7: 'Black'}<jupyter_code>color = {1:'Red', 2:'Orange', 3:'White', 4:'Brown', 5:'Yellow'}

del color[3]

color[7] = 'Black'

color<jupyter_output><empty_output><jupyter_text>Question 5:We have two sets given below. Check if set1 is a subset of set2.set1 = {2, 4, 6}set2 = {2, 4, 6, 8, 10} Expected Output:True<jupyter_code>set1 = {2, 4, 6}
set2 = {2, 4, 6, 8, 10}

set1 <= set2<jupyter_output><empty_output><jupyter_text>Question 6:Merge the two dictionaries given below.myDict1 = {1:'One', 2:'Two', 3:'Three'}myDict2 = {4:'Four', 5:'Five', 6:'Six'} Expected Output:{1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six'}<jupyter_code>myDict1 = {1:'One', 2:'Two', 3:'Three'}
myDict2 = {4:'Four', 5:'Five', 6:'Six'}

myDict1.update(myDict2)

myDict1<jupyter_output><empty_output><jupyter_text>Question 7:We have two sets given below. Print the elements that are present in set1 but not in set2.set1 = {2, 3, 4, 5}set2 = {2, 4, 6, 8} Expected Solution:{3, 5}<jupyter_code>set1 = {2, 3, 4, 5}
set2 = {2, 4, 6, 8}

set1 - set2<jupyter_output><empty_output><jupyter_text>Question 8:We have a dictionary given below. Copy this dictionary into another dictionary 'replica,' and change the value of the key 103 to 'Sally' in the replica dictionary only. Finally, print both the dictionaries.student_details = {101:'Judy', 102:'Victor', 103:'Sam'} Expected Output:{101: 'Judy', 102: 'Victor', 103: 'Sam'}{101: 'Judy', 102: 'Victor', 103: 'Sally'}<jupyter_code>import copy
student_details = {101:'Judy', 102:'Victor', 103:'Sam'}

replica = copy.deepcopy(student_details)
replica[103] = 'Sally'

print(student_details)
print(replica)<jupyter_output>{101: 'Judy', 102: 'Victor', 103: 'Sam'}
{101: 'Judy', 102: 'Victor', 103: 'Sally'}<jupyter_text>Question 9:Remove all the duplicate items from the tuple given below.myTuple = ('Red', 'Blue', 'Green', 'Red', 'Orange', 'Green') Expected Output:{'Blue', 'Green', 'Orange', 'Red'}<jupyter_code>myTuple = ('Red', 'Blue', 'Green', 'Red', 'Orange', 'Green')

mySet = set(myTuple)

mySet<jupyter_output><empty_output><jupyter_text>Question 10:Print the number and the cube of that number in a dictionary from 0 to 5. Expected Output:{0: 0, 1: 1, 2: 8, 3: 27, 4: 64, 5: 125}<jupyter_code>myDict = {x: x**3 for x in range(6)}

print(myDict)<jupyter_output>{0: 0, 1: 1, 2: 8, 3: 27, 4: 64, 5: 125}
{'fraction_non_alphanumeric': 0.180583646344987, 'fraction_numerical': 0.07830106905518636, 'mean_word_length': 6.008097165991903, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 39, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '35213', 'license': 'MIT', 'n_tokens_mistral': 1578, 'n_tokens_neox': 1350, 'n_words': 416, 'path': 'practice-exercise-04-solution.ipynb', 'repo_name': 'LearningJournal/Python-Foundation-Course', 'size': '3461'}