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.
def has_common(lst1, lst2):
for item in lst1:
if item in lst2:
return True
return False
x = [1, 2, 3]
y = [3, 4, 5]
print(has_common(x, y))

Given two lists, write python code to print “True” if the two lists have at least...
USE Python 1. Assign value 555 to the variable x, write code to square the variable x and print out the result. 2. Given a string x, write a program to check if its first character is the same as its last character. If yes, the code should output "True" . 3. We defined two variables, x = 'Python' and y = '3.0'. Write code to concatenate the two numbers (the result should be 'Python3.0').
Using Python: Given a word, write one line of command that print “True” if the first letter is the same as the last letter, and the length of the word is greater than 2. Otherwise, the program prints a “False”. For example, if x='dad', then we expect that line of command to return a “True”.
1) Which of the following is NOT true about a Python
variable?
a) A Python variable must have a value
b) A Python variable can be deleted
c) The lifetime of a Python variable is the whole duration of a
program execution.
d) A Python variable can have the value
None.
2) Given the code segment:
What is the result of executing the code segment?
a) Syntax error
b) Runtime error
c) No error
d) Logic error
3) What...
Exercise 3 – Sets and Set Operations Imagine you have two grocery lists: Grocery Lists List A List B Soap Fish Oranges Pork Loin Bananas Paper Plates Oatmeal Jelly Fish Soap Write python scripts that do the following: Prints names of products common to both lists. Prints names of products that are in at least one of the two lists. Take a screenshot of your python code and the output. Submit your well-labeled Word document that includes all specified elements.
1)Given two lists L1 and L2, create a new list L3 consisting of the first element of L1 and the last element of L2. For example, if L1=[1,2,3] and L2=["a","b","c"], L3 should be [1,"c"] 2)given a string s, create a new string odd_letters that contains only the odd letters of s (two ways to solve this problem are to use slicing, or a while or for loop), i.e. starting at the first letter or the zeroth index: if s="banana", odd_letters...
C# code Arrays and Linked Lists: Write C++/Java/C#/Python code to declare an array of linked lists of any primitive type you want. (Array of size 2020) (This could be based on MSDN libraries or the lab) – you do not need to instantiate any of the linked lists to contain any actual values. Paste your code for that here (this should only be one line) Based on your code or the lab from 4 or your doubly linked list from...
In PYTHON: Write a function that receives a list of integers and returns the number of integers that are larger than the element immediately before them. For example, given [1,2,3,-5,0,-5,-10] the function should return 3 (since 1<2, 2<3, and -5<0).
PYTHON 3 HELP Write a function find_common_elements(list_p,list_q) that accepts two lists, list_p and list_q, as parameters and returns a new list that contains only the elements that are common between two lists (without duplicates). Make sure your program works on two lists of different sizes. Demonstrate your function works by calling it with 2 different pairs of lists. Pseudocode for find_common_elements(list_p,list_q): INITIALIZE empty common_list FOR EACH element e in list_p: IF e is in list_q: ADD e to common_list RETURN...
Write code on best Python style and with appropriate indentation. 1. Given that you have function f that accepts a kwargs argument and does not have a return. You also have a variable d that has been assigned a dictionary. Write a line of code that passes variable d to function f. 2a) Complete the following code to build the states dictionary. The USPresidents.txt file has a number of lines of data, with each line containing two pieces of data:...
Write Python code examples of statements to remove the name at position 2 from the list in problem 32, and to remove one of the remaining names by referencing that name. Write Python code to declare a tuple named stuck that holds the three remaining names from famfri by referencing those names as elemens of famfri. Declare a Python set containing the names of the four seasons. What happens if you declare a set using a list that contains two...