Python - What's the correct Syntax to add a condition in my loop?


I’m trying to apply one style to the odd elements of a RangeSlider, and another style to the even elements of this RangeSlider.

For the even elements, I do it this way:

    i : {
    'label' : available_dates_rangeslider[i], 
    'style':{'transform':'rotate(-90deg)', 'font-size':'10px', 'margin-top':'10px'}
    } for i in range(0, len(available_dates_barchart)) if i %2==0

But how to write the loop so that it adds a style for the “else” ? Still a newbie with python.

I fixed this declaring a function at the top of my code:

def GenerateMarksForRangeSlider():
    for i in range(0, len(available_dates_barchart)):
        if i %2==0:
                'label' : available_dates_rangeslider[i], 
                'style': {'transform':'rotate(-90deg)', 'font-size':'9.25px', 'margin-top':'25px'}
                'label' : available_dates_rangeslider[i], 
                'style': {'transform':'rotate(-90deg)', 'font-size':'9.25px', 'margin-top':'-35px'}
    return marks

and then in my dcc.RangeSlider code:

Dont know if there are better way. But it works and I can display 65 marks on 300px wide screens, which was the goal.

Circular RangeSliders could be interesting for such use, I guess :slight_smile:

1 Like