|
| 1 | +# pylint: disable=missing-function-docstring,pointless-string-statement,expression-not-assigned |
| 2 | + |
| 3 | +""" |
| 4 | + Sets... |
| 5 | +""" |
| 6 | + |
| 7 | +print("Sets...") |
| 8 | + |
| 9 | +states: list[str] = ["Buenos Aires", "Texas", "Madrid", "Houston", "California"] |
| 10 | + |
| 11 | + |
| 12 | +print('\nstates: list[str] = ["Texas", "Madrid", "Houston", "California"]') |
| 13 | + |
| 14 | +print(f"{states=}") |
| 15 | + |
| 16 | +print("\nAppend new state at the end...") |
| 17 | +print('\nstates.append("Berlin")') |
| 18 | + |
| 19 | +states.append("Berlin") |
| 20 | +print(f"{states=}") |
| 21 | + |
| 22 | +print("\nAppend new state at the start...") |
| 23 | +print('\nstates.insert(0, "Chaco")') |
| 24 | + |
| 25 | +states.insert(0, "Chaco") |
| 26 | +print(f"{states=}") |
| 27 | + |
| 28 | +print("\nAppend several states at the end...") |
| 29 | +print('\nstates.extend(["Paris", "Montana"])') |
| 30 | + |
| 31 | +states.extend(["Paris", "Montana"]) |
| 32 | +print(f"{states=}") |
| 33 | + |
| 34 | +print("\nAppend several states at index 4...") |
| 35 | +print('\nstates = [*states[0:4], *["Jujuy", "Formosa"], *states[4:]]') |
| 36 | + |
| 37 | +states = [*states[0:4], *["Jujuy", "Formosa"], *states[4:]] |
| 38 | +print(f"{states=}") |
| 39 | + |
| 40 | +print("\nDelete state at index 3...") |
| 41 | +print("\nstates = [*states[0:3], *states[3 + 1:]]") |
| 42 | + |
| 43 | +states = [*states[0:3], *states[3 + 1 :]] |
| 44 | +print(f"{states=}") |
| 45 | + |
| 46 | +print("\nUpdate state at index 6...") |
| 47 | +print('\nstates[6] = "Miami"') |
| 48 | + |
| 49 | +states[6] = "Miami" |
| 50 | +print(f"{states=}") |
| 51 | + |
| 52 | +print("\nCheck if a state is present...") |
| 53 | +print(f'\nstates.count("Buenos Aires") > 0 => {states.count("Buenos Aires") > 0}') |
| 54 | + |
| 55 | +print(f"{states=}") |
| 56 | + |
| 57 | +print("\nClear saved data...") |
| 58 | +print("\ndata.clear()") |
| 59 | + |
| 60 | +states.clear() |
| 61 | +print(f"{states=}") |
| 62 | + |
| 63 | +print( |
| 64 | + "\n# ---------------------------------------------------------------------------------- #\n" |
| 65 | +) |
| 66 | + |
| 67 | +""" |
| 68 | + Additional challenge... |
| 69 | +""" |
| 70 | + |
| 71 | +print("Additional challenge...") |
| 72 | + |
| 73 | +first_set: set[str] = {"Hello", "TypeScript", "World!"} |
| 74 | +second_set: set[str] = {"By", "TypeScript"} |
| 75 | + |
| 76 | +print(f"\n{first_set=}") |
| 77 | +print(f"{second_set=}") |
| 78 | + |
| 79 | +intersected: set[str] = first_set.intersection(second_set) |
| 80 | + |
| 81 | +print("\nintersected: set[str] = first_set.intersection(second_set)") |
| 82 | +print(f"{intersected=}") |
| 83 | + |
| 84 | +joined: set[str] = first_set.union(second_set) |
| 85 | + |
| 86 | +print("\njoined: set[str] = first_set.union(second_set)") |
| 87 | +print(f"{joined=}") |
| 88 | + |
| 89 | +difference: set[str] = first_set.difference(second_set) |
| 90 | + |
| 91 | +print("\ndifference: set[str] = first_set.difference(second_set)") |
| 92 | +print(f"{difference=}") |
| 93 | + |
| 94 | +symmetric_difference: set[str] = first_set.symmetric_difference(second_set) |
| 95 | + |
| 96 | +print("\nsymmetric_difference: set[str] = first_set.symmetric_difference(second_set)") |
| 97 | +print(f"{symmetric_difference=}") |
0 commit comments