Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
<
=
1
0
,
and a
2
+
b
2
=
c
2
+
d
2
.
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:
lst
1
=
[
"
Spam
"
,
"Trams", "Elbows", "Tops", "Astral"
]
lst
2
=
[
"
Bowels
"
,
"Sample", "Altars", "Stop", "Course", "Smart"
]
Write a list comprehension that returns a list of tuples
(
w
1
,
w
2
)
where w
1
is from lst
1
and w
2
is from
lst
2
and w
1
and w
2
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 python provide code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases With Application To GIS

Authors: Philippe Rigaux, Michel Scholl, Agnès Voisard

1st Edition

1558605886, 978-1558605886

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago