How do I remove the brackets from the result while keeping the function a single line of code?
day_list = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
def day_to_number(inp):
return [day for day in range(len(day_list)) if day_list[day] == inp]
print day_to_number("Sunday")
print day_to_number("Monday")
print day_to_number("Tuesday")
print day_to_number("Wednesday")
print day_to_number("Thursday")
print day_to_number("Friday")
print day_to_number("Saturday")
Output:
[0]
[1]
[2]
[3]
[4]
[5]
[6]
day_to_number
returns a list. return only the element you want instead. if you know there will only be 1 element just grab[0]
– Phillie