Question

Given 2 lists, a and b, containing integers, not necessarily with the same length, Write a...

Given 2 lists, a and b, containing integers, not necessarily with the same length, Write a Python program(Python 3) that returns a list that contains only the elements that are common between the lists a and b (without duplicates).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

l1 = [1, 3, 1, 5, 8, 9, 5, 9, 7]
l2 = [7, 7, 1, 3, 9]
lcommon = list(set(l1) & set(l2))
print(lcommon)

Output:

[1, 3, 9, 7]

Add a comment
Know the answer?
Add Answer to:
Given 2 lists, a and b, containing integers, not necessarily with the same length, Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • use python 2a. Union (1 points) Make a union function which takes in 2 lists as...

    use python 2a. Union (1 points) Make a union function which takes in 2 lists as parameters and returns a list. It should return a list that contain all elements that are in either list. Your results list should contain no duplicates. For example, if the two lists are [1,5,6,5, 2] and [3,5, 1,9] then the result list is (1,5,6,2,3,9). Note that the list sizes don't have to be equal. Note that the input lists could have duplicates, but your...

  • Suppose that we have two unsorted lists of integers A and B. The lists are the...

    Suppose that we have two unsorted lists of integers A and B. The lists are the same size, n. a) Write an algorithm that outputs how many integers occur in both lists. An integer occurs at most once in each given list. For example: if A = [1,2,5,7,13,19] and B = [2,9,13,14,19,22], then we can see that elements {2, 13, 19} occur in both lists, so the output will be 3. b) If the lists were sorted, say how we...

  • 2. Given two unsorted STL lists X and P, write a valid C++ function intersection(X, P)...

    2. Given two unsorted STL lists X and P, write a valid C++ function intersection(X, P) that returns a new list that contains the elements common to both X and P. For example, if X = 5, 2, 1, 4 and P = 4, 5, 7; your algorithm should return a new list containing 5 and 4 (order is not important). Also specify the running time of your algorithm using Big-Oh notation. Hint: As the lists are unsorted, a straightforward...

  • Questions Write a method that returns the union of two array lists of integers using the...

    Questions Write a method that returns the union of two array lists of integers using the following header: public static ArrayList<Integer> union(ArrayList<Integer> list1, ArrayList<Integer> list2) Write a test program that: 1. prompts the user to enter two lists, each with five integers, 2. displays their union numbers separated by exactly one space., and 3. finds the maximum number and the minimum number in the combined list. Here is a sample run of the program. Enter five integers for list1: 5...

  • In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of...

    In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of lists and functions with multiple inputs and multiple outputs. Your task is to implement the separate_and_sort function. This function takes two input parameters: 1. A list containing strings and integers in any order. 2. An optional integer parameter size which controls how many items in the list the function will process. If the length of the list is smaller than the value of size,...

  • . Write a Scheme program for each of the following. Which takes in two lists “lst1” and “lst2”, b...

    . Write a Scheme program for each of the following. Which takes in two lists “lst1” and “lst2”, both of which are individually sorted (in ascending order), and returns a list containing the elements of both lst1 and lst2 in sorted order. Print the final list. Input to the program are “lst1” and “lst2”. For instance, lst1 = (1 3 5 7) and lst2 = (2 4 6 8) output: (1 2 3 4 5 6 7 8)

  • Suppose there are two non-empty list variables of equal length in Python called coords and sides. The variable coords contains sub-lists of size 2, with each of these values representing an x and a y...

    Suppose there are two non-empty list variables of equal length in Python called coords and sides. The variable coords contains sub-lists of size 2, with each of these values representing an x and a y co-ordinate. The variable sides also contains sub-lists of size 2, with each of these values representing firstly the length thern the width of a rectangle. Also assume there is also a function in Python called draw_rectangle which takes as its parameters two integers representing firstly...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other in the sequence. Input The first line contains an integer n...

  • Given two lists, write python code to print “True” if the two lists have at least...

    Given two lists, write python code to print “True” if the two lists have at least one common element. For example, x = [1,2,3], y=[3,4,5], then the program should print “True” since there is a common element 3.

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : i have 15 min to submit the solution please help me   You are given a sequence of n non-zero integers a1,a2,…,an. Determine if the given sequence contains a pair of adjacent elements of the same sign (both negative or both positive). Two elements are called adjacent if they stand next to each other...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT