Link to home
Start Free TrialLog in
Avatar of ltpitt
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?
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

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of gelonida
gelonida
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ltpitt
ltpitt

ASKER

Sorry for the lack of clarity...
Perfect guess in any case :)
To initialize the list by incremented numbers, you can simplify it to balls = list(range(1, 16)).