ltpitt
asked on
Write more pythonic code out of a simple for loop
Hello there,
I would like to make this for loop as pythonic as possible to improve my language knowledge but my implementation does not seems to work.
Can you help?
I would like to make this for loop as pythonic as possible to improve my language knowledge but my implementation does not seems to work.
Can you help?
balls = []
[balls.append([number]) for number in range(1, 16)]
def is_ball_solid(ball):
if ball[0] <9:
ball.append("Solid")
else:
ball.append("Stripe")
result = (is_ball_solid(ball) for ball in balls)
print balls
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To initialize the list by incremented numbers, you can simplify it to balls = list(range(1, 16)).
ASKER
Perfect guess in any case :)