Shortest way to run seven if statements in Python
<p>I have an <code>if</code> statements that checks a number and then return a string value accordingly.</p>

<p><strong>code:</strong></p>

<pre><code>def get_weekday(day):
    if day in ['1', 1]:
        return 'Monday'
    elif day in ['2', 2]:
        return 'Tuesday'
    elif day in ['3', 3]:
        return 'Wednesday'
    elif day in ['4', 4]:
        return 'Thursday'
    elif day in ['5', 5]:
        return 'Friday'
    elif day in ['6', 6]:
        return 'Saturday'
    elif day in ['7', 7]:
        return 'Sunday'
    return 'Invalid day selected'
</code></pre>

<p>The question may appear subjective but I think there should be a <strong>pythonic</strong> and better and shorter and cleaner way of writing this.</p>

<p>I would rather use the <code>get</code> method of a dictionary instead of writing multiple <code>elif</code>s:</p>

<pre><code>def get_weekday(day):
    WEEK = {"1": "Monday",
            "2": "Tuesday",
            "3": "Wednesday",
            "4": "Thursday",
            "5": "Friday",
            "6": "Saturday",
            "7": "Sunday"}
    return WEEK.get(str(day), "Invalid day selected!")
</code></pre>

<p>Converting the day argument explicitly to <code>str</code> ensures both string and integer arguments would work.</p>

python