python logo

Sets

Sets using curly braces { } Example of a Set : mixed_set = {11, 200, 404, 30, "Python", "JavaScript", 99, "Ruby", "Rust"} Sets are unordered collection of elements, meaning that everytime I run the code the order of the items/elements will be print out randomly mixed_set = {11, 200, 404, 30, "Python", "JavaScript", 99, "Ruby", "Rust"} print(type(mixed_set)) print(mixed_set) Sets don’t allow for duplicate elements duplicates = {11, 11, "python", "ruby", 30, 9, 30, "python"} print(duplicates) If I have a List with some duplicates items I can cast it to a Set to remove them duplicate_list = ["python", "java", "ruby", "java", 300, 9, 9, 300, "python", 1, 10] print(duplicate_list) new_set = set(duplicate_list) print(new_set) Set is optimized for mainly to find information in them and for mathematical operations...

March 20, 2022 · 2 min · Kei
python logo

Compound Data Types

Compound Data Type is a data made from collection of various data types like strings, integers, etc. Compound Data Types in Python can be represented by List, Dictionary, Tuple, Set. Tools I can use to work with Compound Data Types are Iterators, For loops, While loops, and other Functions List Using square brackets [ ] The elements are separated by comma Maintain order of the elements Using index to access the elements Mutable, the elements can be change [1, 2, 3, 1, True, "Kei", "Mars", 0....

February 19, 2022 · 1 min · Kei