0
def get_day_type(info):                                                   
    
    day_type = (info[info.find("(")+1:info.find(")")])

    holiday = ["Sun", "Sat"]                              
    if day_type not in holiday:
        day_type = ("weekday")
        return day_type
        
    else:
        day_type = ("weekend")
        return day_type

The problem that it´s printing the type of the first day only and ignore the rest. for example:

print(get_day_type("Normal: 2May2022(mon), 3May2022(tues), 18Mar2021(Sun)"))

it only prints:

weekday

But I want my output to print all types of days. for example :

weekday

weekday

weekend

Note: I need to follow the same format of info input:

Which is ==>clientType: 12May1995(mon), 10May1995(tues), ........etc

1 Answer 1

1

I think this is what you are looking for.

def get_day_type(info):                                                   
    values = info.split(",")
    output = []
    for value in values:
        day_type = (value[value.find("(")+1:value.find(")")])
    
        holiday = ["Sun", "Sat"]                              
        if day_type not in holiday:
            day_type = ("weekday")
            output.append(day_type)
            
        else:
            day_type = ("weekend")
            output.append(day_type)

    return output

print(get_day_type("Normal: 2May2022(mon), 3May2022(tues), 18Mar2021(Sun)"))

output is

weekday
weekday
weekend

It just splits the info on the commas. It then iterates through the list created and uses the code you had to get the weekday or weekend for each item in the list. The outputs are stored in a list and then returned.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you ... it is solved now is there a way to make the output be in list ??
If you change the return to return output, is that what you mean?
Woow ... i hope to be one day like you.. thank you so much
No problem. I edited the answer to reflect this change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.