My QA Projects

QA Projects I was involded.

View on GitHub

set&dict

Sets and dictionaries are unordered collections of items.

They serve different purposes due to their unique properties.

In Common Unordered

In Common Mutability

# Adding elements to a set
my_set.add(6)
print(my_set)  # Output: {1, 2, 3, 4, 5, 6}

# Adding a new key-value pair to a dictionary
my_dict['d'] = 4
print(my_dict)  # Output: {'a': 1, 'b': 2, 'c': 3, 'd': 4}

differences between sets and dictionaries:

Accessing Elements:

# Accessing elements in a set
for element in my_set:
    print(element)  # Output: 1, 2, 3, 4, 5

# Accessing elements in a dictionary
print(my_dict['a'])  # Output: 1

About accessing dictionaries

Sets:

Example

# Creating a set
my_set = {1, 2, 3, 4, 5}
print(my_set)  # Output: {1, 2, 3, 4, 5}

Dictionaries:

Example

# Creating a dictionary
my_dict = {'a': 1, 'b': 2, 'c': 3}
print(my_dict)  # Output: {'a': 1, 'b': 2, 'c': 3}

Data Type Content Type Sequence Mutable defined Order
string characters yes no  
list anything yes yes  
tuple anything yes no  
range integers yes no  
set immutable items no yes unordered collections
dictionary immutable items no yes unordered collections