I am writing a simple secret santa script that selects a "GiftReceiver" and a "GiftGiver" from a list. Two lists and an empty dataframe to be populated are produced:
import pandas as pd
import random
santaslist_receivers = ['Rudolf',
        'Blitzen',
        'Prancer',
        'Dasher',
        'Vixen',
        'Comet'
        ]
santaslist_givers = santaslist_receivers
finalDataFrame = pd.DataFrame(columns = ['GiftGiver','GiftReceiver'])
I then have a while loop that selects random elements from each list to pick a gift giver and receiver, then remove from the respective list:
while len(santaslist_receivers) > 0:
    print (len(santaslist_receivers)) #Used for testing.
    gift_receiver = random.choice(santaslist_receivers)
    santaslist_receivers.remove(gift_receiver)
    print (len(santaslist_receivers)) #Used for testing.
    gift_giver = random.choice(santaslist_givers)
    while gift_giver == gift_receiver:                      #While loop ensures that gift_giver != gift_receiver
        gift_giver = random.choice(santaslist_givers)
    santaslist_givers.remove(gift_giver)
    dummyDF = pd.DataFrame({'GiftGiver':gift_giver,'GiftReceiver':gift_receiver}, index = [0])
    finalDataFrame = finalDataFrame.append(dummyDF)
The final dataframe only contains three elements instead of six:
print(finalDataframe)
returns
    GiftGiver GiftReceiver
0    Dasher      Prancer
0     Comet        Vixen
0    Rudolf      Blitzen
I have inserted two print lines within the while loop to investigate. These print the length of the list santaslist_receivers before and after the removal of an element. The expected return is to see original list length on the first print, then minus 1 on the second print, then the same length again on the first print of the next iteration of the while loop, then so on. Specifically I expect:
6,5,5,4,4,3,3... and so on.
What is returned is
6,5,4,3,2,1
Which is consistent with the DataFrame having only 3 rows, but I do not see the cause of this.
What is the error in my code or my approach?
 
     
    