String information not saving on calendar array Python
<p>I created a script that would let me choose a month, then a day and save the name of a student.But when it loops, all the information previously entered is erased(when choosing another day in the same month). I really don't know how to save the info on the array.
Here's my code, i use Python 3.0:</p>

<pre><code>def chooseDate(dateM, day, month):
            month = [['January'], ['February'],['March'],['April'],['May'],  ['June'],['July'],['August'],['September'],['October'],['November'],['December']]


            for i in range(0,len(month)):
                if dateM in month[i]:
                    print("OK")
                    indexM = i
                    month[indexM] = [[] for _ in range(31)]

                    indexD = day - 1 

                    month[indexM][indexD] = [[str(day), name]]

                    print(month[indexM])




while True:
    choice = str(input("Y or N: "))
    if choice == 'y':
        dateM = str(input("Month: "))
        day = int(input("Day :"))
        name = str(input("Which Student? "))
        chooseDate(dateM, day, name)
    if choice == 'n':
        print(month[indexM])
        break
</code></pre>

<p>Keeping each new student name could get unwieldy quickly using arrays. Instead of the list comprehension making a 2d array for each month, you could try creating a <a href="https://docs.python.org/3.5/tutorial/datastructures.html#dictionaries" rel="nofollow">dictionary</a> for each month instead using <code>day</code> as your key and a list of <code>name</code> as your values. </p>

<pre><code>january = {}
january[1] = ['Student1']
january[2] = ['Student2']
</code></pre>

<p>After a day already has a student in it, use <code>append</code> to add another name to the list:</p>

<pre><code>if 1 in january.keys():
    january[1].append('Student3')

print(january[1])
# ['Student1', 'Student3']
</code></pre>

python arrays calendar sublist