Skip to content

Add sorting of variables by type#3537

Open
naderidkeidek-star wants to merge 1 commit into
mate-academy:masterfrom
naderidkeidek-star:patch-4
Open

Add sorting of variables by type#3537
naderidkeidek-star wants to merge 1 commit into
mate-academy:masterfrom
naderidkeidek-star:patch-4

Conversation

@naderidkeidek-star
Copy link
Copy Markdown

6th Change and Final
lucky_number = 777
pi = 3.14
one_is_a_prime_number = False
name = "Richard"
my_favourite_films = [
"The Shawshank Redemption",
"The Lord of the Rings: The Return of the King",
"Pulp Fiction",
"The Good, the Bad and the Ugly",
"The Matrix",
]
profile_info = ("michel", "michel@gmail.com", "12345678") marks = {
"John": 4,
"Sergio": 3,
}
collection_of_coins = {1, 2, 25}

Create dictionary

sorted_variables = {
"mutable": [],
"immutable": []
}

Put variables into a list

variables = [lucky_number, pi, one_is_a_prime_number, name, my_favourite_films, profile_info, marks, collection_of_coins]

Check each variable type

for variable in variables:
if type(value) in [list, dict, set, tuple]:
sorted_variables["mutable"].append(variable)
else:
sorted_variables["immutable"].append(variable)

print(sorted_variables)

6th Change and Final
lucky_number = 777
pi = 3.14
one_is_a_prime_number = False
name = "Richard"
my_favourite_films = [
    "The Shawshank Redemption",
    "The Lord of the Rings: The Return of the King",
    "Pulp Fiction",
    "The Good, the Bad and the Ugly",
    "The Matrix",
]
profile_info = ("michel", "michel@gmail.com", "12345678")
marks = {
    "John": 4,
    "Sergio": 3,
}
collection_of_coins = {1, 2, 25}

# Create dictionary
sorted_variables = {
    "mutable": [],
    "immutable": []
}

# Put variables into a list
variables = [lucky_number, pi, one_is_a_prime_number, name, my_favourite_films, profile_info, marks, collection_of_coins]

# Check each variable type
for variable in variables:
    if type(value) in [list, dict, set, tuple]:
        sorted_variables["mutable"].append(variable)
    else:
        sorted_variables["immutable"].append(variable)

print(sorted_variables)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant