In: Computer Science
Create a program (or set of programs) which accomplish the following for each complex data type (list,tuple,set,frozenset, dictionary):
And do the following:
Turn in:
PYTHON
1. Using List
2. Using tuple
You can't insert a new element in an existing tuple because it's tuple property that it's unchangeable. And if you want to add a new element then, we can create a new tuple and rename it as the previous tuple.
As we know tuple is unchangeable so, we can't enter a new element in the tuple but, if we really want to do so then we can create a new tuple through slicing and add a new element at a given index and rename it as the previous tuple.
As I said above tuples are unchangeable so we can't modify the existing tuple. But if we really want to add a tuple in a tuple then we can create a new tuple and rename it.
As in previous cases, we can't modify the existing tuple but, we can create a new one and rename it
3. Using Set
We can't add an element in the middle of the set. As there is no predefined function and we can't use slicing in the set.
Since set elements must be hashable, and lists are considered mutable, you cannot add a list to a set. You also cannot add other sets to a set. You can, however, add the elements from lists and sets as demonstrated with the update method.
4. Using frozenset
As its name suggests, we can't modify it once it's declared. but there are some basic set operations like union, intersection, disjoint, etc.. So it's not possible to modify it.
It's NOT POSSIBLE to insert, remove, and modify it. So other cases are irrelevant.
5. Using Dictionary
We can't add a new key in between of existing dictionary but, we can create a new dictionary and perform changes in that dictionary