<jupyter_start><jupyter_text>Question 1:<jupyter_code>A robot has been given a list of movement instructions.
Each instruction is either left, right, up or down, followed by a distance to move. 
The robot starts at [0, 0]. 
You want to calculate where the robot will end up and return its final position as a list.

To illustrate, if the robot is given the following instructions:
    
["right 10", "up 50", "left 30", "down 10"]

It will end up 20 left and 40 up from where it started, so we return [-20, 40].

Examples

track_robot(["right 10", "up 50", "left 30", "down 10"]) [-20, 40]
track_robot([]) [0, 0]

// If there are no instructions, the robot doesn't move.
track_robot(["right 100", "right 100", "up 500", "up 10000"]) [200, 10500]<jupyter_output><empty_output><jupyter_text>Answer :<jupyter_code>import re

def track_robot(lst):
    dic = {"right":0, "up":0, "left":0, "down":0}
    for i in lst:
        k,j = i.split()
        dic[k] += int(j)
    return [dic["right"]-dic["left"], dic["up"]-dic["down"]]

print(track_robot(["right 10", "up 50", "left 30", "down 10"]))
print(track_robot(["right 100", "right 100", "up 500", "up 10000"]))<jupyter_output>[-20, 40]
[200, 10500]<jupyter_text>Question 2:<jupyter_code>Write a function that will return the longest word in a sentence. In cases
where more than one word is found, return the first one.

Examples

find_longest("A thing of beauty is a joy forever.") "forever"
find_longest("Forgetfulness is by all means powerless!") "forgetfulness"
find_longest("\"Strengths\" is the longest and most commonly used word that contains only a single vowel.") 
"strengths"<jupyter_output><empty_output><jupyter_text>Answer :<jupyter_code>import re

def find_longest(str_):
    str_ = re.findall("\w+",str_)
    return max(str_,key=lambda x : len(x))



print(find_longest("A thing of beauty is a joy forever."))
print(find_longest("Forgetfulness is by all means powerless!"))

str_ = "\"Strengths\" is the longest and most commonly used word that contains only a single vowel."
print(find_longest(str_))<jupyter_output>forever
Forgetfulness
Strengths<jupyter_text>Question 3:<jupyter_code>Create a function to check if a candidate is qualified in an imaginary coding 
interview of an imaginary tech startup.
The criteria for a candidate to be qualified in the coding interview is:
    
 1. The candidate should have complete all the questions.
 2. The maximum time given to complete the interview is 120 minutes.
 3. The maximum time given for very easy questions is 5 minutes each.
 4. The maximum time given for easy questions is 10 minutes each.
 5. The maximum time given for medium questions is 15 minutes each.
 6. The maximum time given for hard questions is 20 minutes each.
    
If all the above conditions are satisfied, return "qualified", else return
"disqualified".
You will be given a list of time taken by a candidate to solve a particular
question and the total time taken by the candidate to complete the interview.Given a list ,
in a true condition will always be in the format
[very easy, very easy, easy, easy, medium, medium, hard, hard].

The maximum time to complete the interview includes a buffer time of 20
minutes.

Examples

interview([5, 5, 10, 10, 15, 15, 20, 20], 120) "qualified"
interview([2, 3, 8, 6, 5, 12, 10, 18], 64) "qualified"
interview([5, 5, 10, 10, 25, 15, 20, 20], 120) "disqualified"
# Exceeded the time limit for a medium question.
interview([5, 5, 10, 10, 15, 15, 20], 120) "disqualified"
# Did not complete all the questions.
interview([5, 5, 10, 10, 15, 15, 20, 20], 130) "disqualified"
# Solved all the questions in their respected time limits but exceeded the total time limit of the interview<jupyter_output><empty_output><jupyter_text>Answer :<jupyter_code>def interview(lst,time):
    
    length = len(lst)
    if length<8 or time>120:
        return "disqualified"
    for i, j in zip(range(0,length,2),[5,10,15,20]):
        if (lst[i]>j or lst[i+1]>j):
            return "disqualified"
        
    return "qualified"


print(interview([5, 5, 10, 10, 15, 15, 20, 20], 120))
print(interview([2, 3, 8, 6, 5, 12, 10, 18], 64))
print(interview([5, 5, 10, 10, 25, 15, 20, 20], 120))
print(interview([5, 5, 10, 10, 15, 15, 20], 120))
print(interview([5, 5, 10, 10, 15, 15, 20, 20], 130))<jupyter_output>qualified
qualified
disqualified
disqualified
disqualified<jupyter_text>Question 4:<jupyter_code>Write a function that divides a list into chunks of size n, where n is the
length of each chunk.

Examples

chunkify([2, 3, 4, 5], 2) [[2, 3], [4, 5]]
chunkify([2, 3, 4, 5, 6], 2) [[2, 3], [4, 5], [6]]
chunkify([2, 3, 4, 5, 6, 7], 3) [[2, 3, 4], [5, 6, 7]]
chunkify([2, 3, 4, 5, 6, 7], 1) [[2], [3], [4], [5], [6], [7]]
chunkify([2, 3, 4, 5, 6, 7], 7) [[2, 3, 4, 5, 6, 7]]<jupyter_output><empty_output><jupyter_text>Answer :<jupyter_code>def chunkify(lst,n):
    
    chunk = []
    for i in range(0,len(lst),n):
        chunk.append(lst[i:i+n])
        
    return chunk


print(chunkify([2, 3, 4, 5], 2))
print(chunkify([2, 3, 4, 5, 6], 2))
print(chunkify([2, 3, 4, 5, 6, 7], 3))
print(chunkify([2, 3, 4, 5, 6, 7], 1))
print(chunkify([2, 3, 4, 5, 6, 7], 7))<jupyter_output>[[2, 3], [4, 5]]
[[2, 3], [4, 5], [6]]
[[2, 3, 4], [5, 6, 7]]
[[2], [3], [4], [5], [6], [7]]
[[2, 3, 4, 5, 6, 7]]<jupyter_text>Question 5:<jupyter_code>You are given a list of strings consisting of grocery items, with prices in
parentheses. Return a list of prices in float format.

Examples

get_prices(["salad ($4.99)"]) [4.99]

get_prices([
 "artichokes ($1.99)",
 "rotiserrie chicken ($5.99)",
 "gum ($0.75)"
])
 [1.99, 5.99, 0.75]
    
get_prices([
 "ice cream ($5.99)",
 "banana ($0.20)",
 "sandwich ($8.50)",
 "soup ($1.99)"
])
 [5.99, 0.2, 8.50, 1.99]<jupyter_output><empty_output><jupyter_text>Answer :<jupyter_code>import re

def get_prices(lst):
    return [float(s[s.index("(")+2:s.index(")")]) for s in lst]
    #return [float(i) for i in re.findall("\d+.\d+",items)]

print(get_prices(["salad ($4.99)"]))
                  
print(get_prices([
 "artichokes ($1.99)",
 "rotiserrie chicken ($5.99)",
 "gum ($0.75)"
]))
                  
print(get_prices([
 "ice cream ($5.99)",
 "banana ($0.20)",
 "sandwich ($8.50)",
 "soup ($1.99)"
]))<jupyter_output>[4.99]
[1.99, 5.99, 0.75]
[5.99, 0.2, 8.5, 1.99]
{'fraction_non_alphanumeric': 0.16036837091140044, 'fraction_numerical': 0.07939028262940616, 'mean_word_length': 4.302188552188552, 'pattern_counts': {'":': 4, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '35909', 'license': 'MIT', 'n_tokens_mistral': 2717, 'n_tokens_neox': 2290, 'n_words': 836, 'path': 'Python Advance Programming Assignment/Assignment_18.ipynb', 'repo_name': 'kpsanjeet/Python-Programming-Basic-Assignment', 'size': '6298'}