Write A Simple List Comprehension That Generates The First 5 Even Numbers As A List
Write A Simple List Comprehension That Generates The First 5 Even Numbers As A List
PROGRAMMING
3.0 Marks
Write a simple list comprehension that generates the first 5 even numbers as a list.
For example:
Output
[2, 4, 6, 8, 10]
print(l)
print(w)
Write all possible 2 letter permutations of the word 'hello', this time show only
the unique ones
s="hello"
print(w)
Using a list comprehension, create a list of tuples of the form (x, x*x,
x*x*x) for the first 5 integers starting at 1.
l=[(x,x*x,x*x*x) for x in range(1,6)]
print(l)
Create a dictionary with the keys being the lowercase characters of the
English alphabet and the value being an empty list.
For example
Output
{'a': [],
'b': [],
....
}
z={x:[] for x in 'abcdefghijklmnopqrstuvwxyz'}
print(z)
Create a dictionary with the keys being the lowercase words (only the first
three characters) denoting the day of the week and the value being an integer
corresponding to each with 0 being 'mon' and 6 'sun' .
For example
Output
{'mon': 0,
'sun': 6
}
z={x:i for i, x in enumerate(('mon','tues','thurs','friday','saturday','sunday'))}
print(z)
print(max(r))