|
| 1 | +# Ejercicio |
| 2 | +from functools import reduce |
| 3 | +from itertools import count, islice |
| 4 | + |
| 5 | + |
| 6 | +def iteration_with_for(): |
| 7 | + for index in range(1, 11): |
| 8 | + print(index) |
| 9 | + |
| 10 | + |
| 11 | +def iteration_with_while(): |
| 12 | + index = 1 |
| 13 | + while index <= 10: |
| 14 | + print(index) |
| 15 | + index += 1 |
| 16 | + |
| 17 | + |
| 18 | +def iteration_with_for_in(): |
| 19 | + array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
| 20 | + for index in array: |
| 21 | + print(index) |
| 22 | + |
| 23 | + |
| 24 | +# Extra |
| 25 | +def iteration_with_for_each(): |
| 26 | + array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] |
| 27 | + for element in array: |
| 28 | + print(element) |
| 29 | + |
| 30 | + |
| 31 | +def recursive_count(number=1): |
| 32 | + if number <= 10: |
| 33 | + print(number) |
| 34 | + recursive_count(number + 1) |
| 35 | + |
| 36 | + |
| 37 | +def iteration_with_comprehension(): |
| 38 | + print(*[index for index in range(1, 11)], sep="\n") |
| 39 | + |
| 40 | + |
| 41 | +def iteration_with_map(): |
| 42 | + print(*map(lambda x: x, range(1, 11))) |
| 43 | + |
| 44 | + |
| 45 | +def iteration_with_filter(): |
| 46 | + print(*filter(lambda x: True if x <= 10 else False, range(1, 101))) |
| 47 | + |
| 48 | + |
| 49 | +def iteration_with_reduce(): |
| 50 | + print(reduce(lambda x, y: x + y, range(1, 11))) |
| 51 | + |
| 52 | + |
| 53 | +def iteration_with_islice(): |
| 54 | + print(*islice(count(1), 10)) |
| 55 | + |
| 56 | + |
| 57 | +def iteration_with_zip(): |
| 58 | + print(*zip(range(1, 11), range(11, 21))) |
| 59 | + |
| 60 | + |
| 61 | +def iteration_with_enumerate(): |
| 62 | + print(*enumerate([x for x in range(1, 11)], 1)) |
| 63 | + |
| 64 | + |
| 65 | +def iteration_with_comprehension_2(): |
| 66 | + print(*[(x, y) for x in range(1, 11) for y in range(x, 11)]) |
| 67 | + |
| 68 | + |
| 69 | +def iteration_with_comprehension_3(): |
| 70 | + print(*[(x, y) for x in range(1, 11) for y in range(x, 11) if x != y]) |
| 71 | + |
| 72 | + |
| 73 | +def iteration_with_comprehension_4(): |
| 74 | + print( |
| 75 | + *[ |
| 76 | + (x, y, z) |
| 77 | + for x in range(1, 11) |
| 78 | + for y in range(x, 11) |
| 79 | + for z in range(y, 11) |
| 80 | + if x != y != z |
| 81 | + ] |
| 82 | + ) |
| 83 | + |
| 84 | + |
| 85 | +def iteration_with_comprehension_5(): |
| 86 | + print( |
| 87 | + *[ |
| 88 | + (x, y, z) |
| 89 | + for x in range(1, 11) |
| 90 | + for y in range(x, 11) |
| 91 | + for z in range(y, 11) |
| 92 | + if x != y != z and x < y < z |
| 93 | + ] |
| 94 | + ) |
| 95 | + |
| 96 | + |
| 97 | +def iteration_with_comprehension_6(): |
| 98 | + print( |
| 99 | + *[ |
| 100 | + (x, y, z) |
| 101 | + for x in range(1, 11) |
| 102 | + for y in range(x, 11) |
| 103 | + for z in range(y, 11) |
| 104 | + if x != y != z and x > y > z |
| 105 | + ] |
| 106 | + ) |
| 107 | + |
| 108 | + |
| 109 | +def iteration_with_comprehension_7(): |
| 110 | + print( |
| 111 | + *[ |
| 112 | + (x, y, z) |
| 113 | + for x in range(1, 11) |
| 114 | + for y in range(x, 11) |
| 115 | + for z in range(y, 11) |
| 116 | + if x != y != z and x == y == z |
| 117 | + ] |
| 118 | + ) |
| 119 | + |
| 120 | + |
| 121 | +def iteration_with_comprehension_8(): |
| 122 | + print( |
| 123 | + *[ |
| 124 | + (x, y, z) |
| 125 | + for x in range(1, 11) |
| 126 | + for y in range(x, 11) |
| 127 | + for z in range(y, 11) |
| 128 | + if x != y != z and x < y > z |
| 129 | + ] |
| 130 | + ) |
| 131 | + |
| 132 | + |
| 133 | +def iteration_with_comprehension_9(): |
| 134 | + print( |
| 135 | + *[ |
| 136 | + (x, y, z) |
| 137 | + for x in range(1, 11) |
| 138 | + for y in range(x, 11) |
| 139 | + for z in range(y, 11) |
| 140 | + if x != y != z and x > y < z |
| 141 | + ] |
| 142 | + ) |
| 143 | + |
| 144 | + |
| 145 | +def iteration_with_comprehension_10(): |
| 146 | + print( |
| 147 | + *[ |
| 148 | + (x, y, z) |
| 149 | + for x in range(1, 11) |
| 150 | + for y in range(x, 11) |
| 151 | + for z in range(y, 11) |
| 152 | + if x != y != z and x < y == z |
| 153 | + ] |
| 154 | + ) |
| 155 | + |
| 156 | + |
| 157 | +def iteration_with_comprehension_11(): |
| 158 | + print( |
| 159 | + *[ |
| 160 | + (x, y, z) |
| 161 | + for x in range(1, 11) |
| 162 | + for y in range(x, 11) |
| 163 | + for z in range(y, 11) |
| 164 | + if x != y != z and x > y == z |
| 165 | + ] |
| 166 | + ) |
| 167 | + |
| 168 | + |
| 169 | +if __name__ == "__main__": |
| 170 | + print("Con For") |
| 171 | + iteration_with_for() |
| 172 | + print("Con While") |
| 173 | + iteration_with_while() |
| 174 | + print("Con For In") |
| 175 | + iteration_with_for_in() |
| 176 | + print("Con For Each") |
| 177 | + iteration_with_for_each() |
| 178 | + print("Con Recursividad") |
| 179 | + recursive_count() |
| 180 | + print("Con list comprehension") |
| 181 | + iteration_with_comprehension() |
| 182 | + print("Con Map") |
| 183 | + iteration_with_map() |
| 184 | + print("Con Filter") |
| 185 | + iteration_with_filter() |
| 186 | + print("Con Reduce") |
| 187 | + iteration_with_reduce() |
| 188 | + print("Con Islice") |
| 189 | + iteration_with_islice() |
| 190 | + print("Con Zip") |
| 191 | + iteration_with_zip() |
| 192 | + print("Con Enumerate") |
| 193 | + iteration_with_enumerate() |
| 194 | + print("Con Comprehension v2") |
| 195 | + iteration_with_comprehension_2() |
| 196 | + print("Con Comprehension v3") |
| 197 | + iteration_with_comprehension_3() |
| 198 | + print("Con Comprehension v4") |
| 199 | + iteration_with_comprehension_4() |
| 200 | + print("Con Comprehension v5") |
| 201 | + iteration_with_comprehension_5() |
| 202 | + print("Con Comprehension v6") |
| 203 | + iteration_with_comprehension_6() |
| 204 | + print("Con Comprehension v7") |
| 205 | + iteration_with_comprehension_7() |
| 206 | + print("Con Comprehension v8") |
| 207 | + iteration_with_comprehension_8() |
| 208 | + print("Con Comprehension v9") |
| 209 | + iteration_with_comprehension_9() |
| 210 | + print("Con Comprehension v10") |
| 211 | + iteration_with_comprehension_10() |
| 212 | + print("Con Comprehension v11") |
| 213 | + iteration_with_comprehension_11() |
0 commit comments