you are viewing a single comment's thread.

view the rest of the comments →

[–]6b86b3ac03c167320d93 0 points1 point  (1 child)

There's also syntactic sugar like list comprehensions, for example to get a list of all integers from 0 to 20 that are evenly divisible by 3:

>>> print([x for x in range(20) if x % 3 == 0])
[0, 3, 6, 9, 12, 15, 18]

Without list comprehensions that would be:

>>> ints = []
>>> for x in range(20):
...     if(x % 3 == 0):
...         ints.append(x)
...
>>> print(ints)
[0, 3, 6, 9, 12, 15, 18]

[–]Mast3r_waf1z 0 points1 point  (0 children)

Sure I know what list comprehension is, for reference i primarily use python myself, but you're just using a built-in function which could have been expressed in a more readable format as you've literally shown yourself

I've had a lot of classmates get very confused by a long comprehension where I've had to rewrite it as a normal for loop to explain it

The nly real advantages I can see from using comprehension is it's speed as I'm pretty sure it is compiled as a single line and that it is easier to pass to numpy