<jupyter_start><jupyter_text>Dance Card Example==================Given a list of gentlemen and ladies, produce a list of partners for 8 dances for each of the dancers.  Approach--------Use a simple random assortment, and rotate the list for each of the 8 dances.<jupyter_code># comments are preceeded by a pound sign (this line is a comment)
# a python list is surrounded by backets, [ ], and is separated by commas
# manually assign the gentlemen's names:
gentlemen = [
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>"]
# a list of ladies:
ladies = [
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>",
    "<NAME>"]
len(ladies), len(gentlemen) # let's see if they are the same length...<jupyter_output><empty_output><jupyter_text>So, now that we have our lists, let's reverse the last and first names for better alphabetizing ...<jupyter_code># Python provides an intuitive way to loop over a list...
gentlemen_last_first = [] # create an empty list
for man in gentlemen:  # A loop ... this is actually an extremely powerful concept
    first, last = man.split(" ") # indentation indicates a 'code block.' Whitespace is important in Python
    gentlemen_last_first.append("{0}, {1}".format(last, first)) # wait, what's going on here? ... string formatting<jupyter_output><empty_output><jupyter_text>**NB:** There is a thourough introduction to string formatting at the excellent [dive into python] page.  Among other things, it explains that in the above string "{0}, {1}", the curly brackets and numbers (0 and 1) are just placeholders whose values are replaced by the arguments of the format method that is called on the string.[dive into python]: http://www.diveintopython3.net/strings.html<jupyter_code>gentlemen_last_first
# Python provides an intuitive way to loop over a list...
ladies_last_first = [] # create an empty list
for lady in ladies:  # A loop ... this is actually an extremely powerful concept
    first, last = lady.split(" ") # indentation indicates a 'code block.' Whitespace is important in Python
    ladies_last_first.append("{0}, {1}".format(last, first))
ladies_last_first
gentlemen_last_first.sort()
ladies_last_first.sort()
ladies_last_first
import random # let's bring in some code from the random built-in library of python
random.shuffle(ladies_last_first)
ladies_last_first
dances = ["mix", "mix", "mix", "mix", "mix", "mix", "Shoe Dance"] # the list of dances

# initialize data structures
gentlemen_dances = {}
ladies_dances = {}

for man in gentlemen_last_first:
    gentlemen_dances[man] = []
for lady in ladies_last_first:
    ladies_dances[lady] = []

for dance in dances:
    #print "#####", dance, "########"
    count = 0
    for man in gentlemen_last_first:
        if dance == "mix":
            gentlemen_dances[man].append(ladies_last_first[count])
            ladies_dances[ladies_last_first[count]].append(man)
            
        else:
            gentlemen_dances[man].append(dance)
            ladies_dances[ladies_last_first[count]].append(dance)
        count += 1
    if dance == "mix":
        gentlemen_last_first.insert(0, gentlemen_last_first.pop(-1))
        
gentlemen_dances
#save result for dudes
fh = open("./dancecards-gentlemen.txt", 'wa')
for man in gentlemen_last_first:
    fh.write("".join(["\n~", man, "~\n"]))
    d_cnt = 1
    for partner in gentlemen_dances[man]:
        fh.write(str(d_cnt) + ". " + partner + "\n")
        d_cnt += 1
fh.close()
#save result for ladies
fh = open("./dancecards-ladies.txt", 'wa')
for lady in ladies_last_first:
    fh.write("".join(["\n~", lady, "~\n"]))
    d_cnt = 1
    for partner in ladies_dances[lady]:
        fh.write(str(d_cnt) + ". " + partner + "\n")
        d_cnt += 1
fh.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15353293413173652, 'fraction_numerical': 0.004550898203592815, 'mean_word_length': 3.490322580645161, 'pattern_counts': {'":': 2, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '129786', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1366, 'n_tokens_neox': 1348, 'n_words': 420, 'path': '03_dance_card_example.ipynb', 'repo_name': 'tvaught/compintro', 'size': '4471'}