Converts all possible For loops to comprehension versions to speed up code. Still a work in progress. Pure python implementation currently.
- variable mutation ex:
.append(variable + "world")
||.append(int(variable))
- class methods ex:
classy.method(x) for x in classy.attributes
- list comprehensions nested
[[y for y in x if y is None] for x in lista]
# For loop
squares = []
for i in range(1, 11):
squares.append(i ** 2)
Converts to...
[i for i in range(1, 11)]
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
evens = []
for num in numbers:
if num % 2 == 0:
evens.append(num)
Converts to...
[num for num in numbers if num % 2 == 0]
names = ['Alice', 'Bob', 'Charlie']
ages = [30, 25, 35]
people = []
for name, age in zip(names, ages):
people.append((name, age))
Converts to...
[(name, age) for name, age in zip(names, ages)]
text = "hello world"
unique_chars = []
for char in text:
if char not in unique_chars:
unique_chars.append(char)
Converts to...
[char for char in text if char not in unique_chars]
names = ['Alice', 'Bob', 'Charlie']
ages = [30, 25, 35]
people = []
for name, age in zip(names, ages):
people.append(age)
Converts to...
[name for name, age in zip(names, ages)]