QuestionQuestion

Write the function common(list1, list2) that takes two lists of numbers, list1 and list2, and returns (not prints) a new list containing only the elements that are common between the two lists in ascending order (without duplicates). Make sure your code works on lists of different sizes.
Your code should not mutate the given lists. Tip: the sort method could be useful here. [2.5pts] Write the function pairs(list1, list2) that takestwo lists of items, list1 and list2, and returns (not prints) a new list that contains lists with the k-th elements of the two lists coupled together.
You can assume the lengths of the two lists are the same.
[5pts] Write the function successorWords(file), where file is a string that contains the name of a txt file that contains multiple strings. This function returns (not prints) a dictionary whose keys are included words (as is), and values are lists of successors to those words. The first word of the txt file is always a successor to ".". Be careful with contraction words. The starter code already contains the code to read the txt file, just make sure the file is in the same directory as your .py file. Note that you have to write your code in two places, before reading the file and after Tip: isalnum, the join method and slicing could be useful here.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

def common(list1, list2):
    """
       >>> common([12,3,5,8,90,11,44,66,8,9,34,56,-1,0,5,3333,3,2,1],[12,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,44])
       [1, 3, 12, 44]
       >>> common([1,2,3],[4,5,6])
       []
       >>> common(1, [3.5]) is None
       True
    """
   
    # --- YOU CODE STARTS HERE
   
    if isinstance(list1, list) == False:
       return None

      
    if isinstance(list2, list) == False:
       return None
   
   
    l1=list1
    l2=list2
   
    result=[]
    for x in range(len(l1)):
       for y in range(len(l2)):
            if l1[x]==l2[y]:
                flag = 0
                for z in range(len(result)):
                   if l1[x] == result[z]:
                        flag = 1
               
                if flag == 0:
                   result.append(l1[x])
                              
    result.sort()
    return result...

By purchasing this solution you'll be able to access the following files:
article.txt and starter.py.

50% discount

Hours
Minutes
Seconds
$80.00 $40.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats