Question: code in pythonfa ) Write a list comprehension that returns all tuples ( a , b , c , d ) , with a ,

code in pythonfa) Write a list comprehension that returns all tuples (a,b,c,d ), with a,b,c,d distinct integers, such that
1<=a,b,c,d<=10, and a2+b2=c2+ d2.
b) Consider a list of strings, like this: ['One', 'SEVEN', 'three', 'two', 'Ten']. Write a list comprehension
that produces a list with tuples where the first element of the tuple is lowercase version of a string in
the initial list, the second element of the tuple is the length of the element of the initial list, and the
resulting list contains only tuples for strings with the length shorter than five characters.
For our example the list comprehension should return [(one,3),(two,3), 'ten', 3)].
c) Consider a list of full names formatted Firstname Middlename Lastname, like this:
names =['Christopher Ashton Kutcher', 'Elizabeth Stamatina Fey']
Write a list comprehension that produces a list with the full names in this format: Firstname M.
Lastname. The resulting list should look like ['Christopher A. Kutcher', 'Elizabeth S. Fey']. The list
comprehension should work for any list names with the proper format.
d) Consider these two lists of strings:
lst1=["Spam", "Trams", "Elbows", "Tops", "Astral"]
lst2=["Bowels", "Sample", "Altars", "Stop", "Course", "Smart"]
Write a list comprehension that returns a list of tuples (w1, w2) where w1 is from lst1 and w2 is from
lst2 and w1 and w2 are anagrams (case insensitive).
For the lists above, the anagram pairs are in this list:
[('Trams', 'Smart'),('Elbows', 'Bowels'),('Tops', 'Stop'),('Astral', 'Altars')]
e) Consider a list of distinct strings like this one:
s =['one', 'two', 'three']
Write a dictionary comprehension that returns a dictionary that maps each string from s to its length.
Example: {'one': 3, 'two': 3, 'three': 5}
f) Write a dictionary comprehension that uses a string in a variable called text and that returns a
dictionary with entries i:c where i is the index of character c in text only for characters c that are vowels
(a e i o u). Checking for vowels is case insensitive.
Example: text = "Hello world"
The resulting dictionary is {1: 'e',4: 'o',7: 'o'}code in oythio

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!