<jupyter_start><jupyter_text>Assignment 15 Solutions  1. Write a function that returns True if a given name can generate an array of words.**Examples:**   `anagram("<NAME>", ["injures", "ebb", "it"]) ➞ True`    `anagram("<NAME>", ["ornamental", "pita"]) ➞ True`   `anagram("<NAME>", ["chirps", "rat"]) ➞ False`   ` Not all letters are used`   `anagram("<NAME>", ["jog", "meld", "bluffs"]) ➞ False`   ` "s" does not exist in the original name`<jupyter_code>def anagram(in_string,in_list):
    in_string_list = list(in_string.lower())
    in_string_list.remove(' ')
    not_exist_list = []
    output = False
    for item in in_list:
        for ele in item:
            if ele in in_string_list:
                in_string_list.remove(ele)
            else:
                not_exist_list.append(ele)
    if len(in_string_list) == 0 and len(not_exist_list) == 0:
        output = True
    print(f'anagram{in_string,in_list} ➞ {output}')
            
anagram("<NAME>", ["injures", "ebb", "it"])
anagram("<NAME>", ["ornamental", "pita"])
anagram("<NAME>", ["chirps", "rat"])
anagram("<NAME>", ["jog", "meld", "bluffs"])<jupyter_output>anagram('<NAME>', ['injures', 'ebb', 'it']) ➞ True
anagram('<NAME>', ['ornamental', 'pita']) ➞ True
anagram('<NAME>', ['chirps', 'rat']) ➞ False
anagram('<NAME>', ['jog', 'meld', 'bluffs']) ➞ False<jupyter_text>2. Given an array of users, each defined by an object with the following properties: name, score, reputation create a function that sorts the array to form the correct leaderboard.The leaderboard takes into consideration the score of each user of course, but an emphasis is put on their reputation in the community, so to get the trueScore, you should add the reputation multiplied by 2 to the score.Once you know the trueScore of each user, sort the array according to it in descending order.**Examples:**   `leaderboards([  { "name": "a", "score": 100, "reputation": 20 },  { "name": "b", "score": 90, "reputation": 40 },  { "name": "c", "score": 115, "reputation": 30 },]) ➞ [  { "name": "c", "score": 115, "reputation": 30 },   trueScore = 175  { "name": "b", "score": 90, "reputation": 40 },    trueScore = 170  { "name": "a", "score": 100, "reputation": 20 }    trueScore = 140]`<jupyter_code>def leaderboards(in_list):
    temp_dict = {}
    out_list = []
    for ele in in_list:
        temp_dict[(ele['reputation']*2)+ele['score']] = ele
    for ele in sorted(temp_dict.keys(),reverse=True):
        out_list.append(temp_dict[ele])
    print(f'leaderboards({in_list}) ➞ {out_list}')
    
leaderboards([
  { "name": "a", "score": 100, "reputation": 20 },
  { "name": "b", "score": 90, "reputation": 40 },
  { "name": "c", "score": 115, "reputation": 30 },
])<jupyter_output>leaderboards([{'name': 'a', 'score': 100, 'reputation': 20}, {'name': 'b', 'score': 90, 'reputation': 40}, {'name': 'c', 'score': 115, 'reputation': 30}]) ➞ [{'name': 'c', 'score': 115, 'reputation': 30}, {'name': 'b', 'score': 90, 'reputation': 40}, {'name': 'a', 'score': 100, 'reputation': 20}]<jupyter_text>3. Create a function that, given a phrase and a number of letters guessed, returns a string with hyphens - for every letter of the phrase not guessed, and each letter guessed in place.**Examples:**   `hangman("helicopter", ["o", "e", "s"]) ➞ "-e---o--e-"`  `hangman("tree", ["r", "t", "e"]) ➞ "tree"`  `hangman("Python rules", ["a", "n", "p", "r", "z"]) ➞ "P----n r----"`  `hangman("He"s a very naughty boy!", ["e", "a", "y"]) ➞ "-e"- a -e-y -a----y –y!"`<jupyter_code>def hangman(in_string,in_list):
    out_string = ''
    for ele in range(len(in_string)):
        if in_string[ele].lower() in in_list:
            out_string += in_string[ele]
        elif in_string[ele] in '"! ':
            out_string += in_string[ele]
        else:
            out_string += '-'
    print(f'hangman{in_string,in_list} ➞ {out_string}')
        
hangman("helicopter", ["o", "e", "s"])
hangman("tree", ["r", "t", "e"])
hangman("Python rules", ["a", "n", "p", "r", "z"])
hangman("He\"s a very naughty boy!", ["e", "a", "y"])<jupyter_output>hangman('helicopter', ['o', 'e', 's']) ➞ -e---o--e-
hangman('tree', ['r', 't', 'e']) ➞ tree
hangman('Python rules', ['a', 'n', 'p', 'r', 'z']) ➞ P----n r----
hangman('He"s a very naughty boy!', ['e', 'a', 'y']) ➞ -e"- a -e-y -a----y --y!<jupyter_text>4. The Collatz sequence is as follows:  - Start with some given integer n.  - If it is even, the next number will be n divided by 2.  - If it is odd, multiply it by 3 and add 1 to make the next number.  - The sequence stops when it reaches 1.According to the Collatz conjecture, it will always reach 1. If that's true, you can construct a finite sequence following the aforementioned method for any given integer.Write a function that takes in an integer n and returns the highest integer in the corresponding Collatz sequence.**Examples:**   `max_collatz(10) ➞ 16`  ` Collatz sequence: 10, 5, 16, 8, 4, 2, 1``max_collatz(32) ➞ 32`  ` Collatz sequence: 32, 16, 8, 4, 2, 1``max_collatz(85) ➞ 256`  ` Collatz sequence: 85, 256, 128, 64, 32, 16, 8, 4, 2, 1`<jupyter_code>def max_collatz(in_num):
    out_list = []
    out_list.append(in_num)
    temp_in_num = in_num
    while True:
        if temp_in_num%2 == 0:
            temp_in_num /= 2
        else:
            temp_in_num = (temp_in_num*3)+1
        out_list.append(int(temp_in_num))
        if temp_in_num ==1:
            break
            
    x= str(out_list)
    print(f'max_collatz({in_num}) ➞ {max(out_list)}')

max_collatz(10)
max_collatz(32)
max_collatz(85)<jupyter_output>max_collatz(10) ➞ 16
max_collatz(32) ➞ 32
max_collatz(85) ➞ 256<jupyter_text>5. Write a function that sorts a list of integers by their digit length in descending order, then settles ties by sorting numbers with the same digit length in ascending order.**Examples:**   `digit_sort([77, 23, 5, 7, 101]) ➞ [101, 23, 77, 5, 7]`  `digit_sort([1, 5, 9, 2, 789, 563, 444]) ➞ [444, 563, 789, 1, 2, 5, 9]`  `digit_sort([53219, 3772, 564, 32, 1]) ➞ [53219, 3772, 564, 32, 1]`<jupyter_code>def digit_sort(in_list):
    max_len = len(str(max(in_list)))
    output = []
    for item in range(max_len,0,-1):
        temp = []
        for ele in in_list:
            if len(str(ele)) == item:
                temp.append(ele)
        output.extend(sorted(temp))
    print(f'digit_sort({in_list}) ➞ {output}')
    
digit_sort([77, 23, 5, 7, 101])
digit_sort([1, 5, 9, 2, 789, 563, 444])
digit_sort([53219, 3772, 564, 32, 1])<jupyter_output>digit_sort([77, 23, 5, 7, 101]) ➞ [101, 23, 77, 5, 7]
digit_sort([1, 5, 9, 2, 789, 563, 444]) ➞ [444, 563, 789, 1, 2, 5, 9]
digit_sort([53219, 3772, 564, 32, 1]) ➞ [53219, 3772, 564, 32, 1]
{'fraction_non_alphanumeric': 0.1923769507803121, 'fraction_numerical': 0.05327130852340936, 'mean_word_length': 3.770937723693629, 'pattern_counts': {'":': 27, '<': 28, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '483889', 'license': 'MIT', 'n_tokens_mistral': 2838, 'n_tokens_neox': 2452, 'n_words': 776, 'path': 'Python Advance Programming/Advance Programming Assignment 15.ipynb', 'repo_name': 'Sayan97/Python', 'size': '6748'}