ITEC-425 / SENG-425: Python Programming Lab Lab 8: Lists and Dictionaries Task 1
ITEC-425 / SENG-425: Python Programming Lab Lab 8: Lists and Dictionaries Task 1
ITEC-425 / SENG-425: Python Programming Lab Lab 8: Lists and Dictionaries Task 1
In [1]:
# method 1 using for loop
Task 2
Rewrite the above Python code, using list comprehension method, to print the numbers in
the list given below after removing even numbers from it.
In [2]:
# method 2 - using list comprehension
Task 3
Write Python code that takes a list of nums and displays the product of all numbers in the
lsit.
In [3]:
num_list = [3, 1, 18, 4, 11, 10, 6, 20]
prod = 1
for num in num_list:
prod = prod * num
print('num_list=', num_list)
print('product of numbers:', prod)
Task 4
Write python code to do the following, using the list given below:
In [4]:
# write your code here
Task 5
Write Python code to take a list of characters and convert it into a string.
In [5]:
# write your code here
Task 6
Write Python code that takes the two list given below, and joins them to create a new list,
sort the new list and display it.
Expected output:
In [7]:
# write your code here
Task 7
Write Python code that asks the user to input a string message, and uses a dictionary to
create a word frequency map.
In [8]:
msg = input("Enter your message:")
words = msg.split()
wd_counts = dict()
for w in words:
wd_counts[w] = wd_counts.get(w, 0) + 1
Task 7
Write Python to that uses the given dictionary and does the following:
In [9]:
# write your code here