0% found this document useful (0 votes)
10 views2 pages

Exercises - Week 6-9

Uploaded by

tanln0224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Exercises - Week 6-9

Uploaded by

tanln0224
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

1) Write Python programs to:

- Enter the list containing numbers


- Calculate the sum of all items in a list
- Calculate the multiple of all items in a list
- Find the largest number in a list
- Find the smallest number in a list
- Check if each number is prime in a given list of numbers. Return True if all
numbers are prime otherwise False.
2) Write a Python program to count the number of strings from a given list of strings.
The string length is 2 or more and the first and last characters are the same.

Sample List : ['abc', 'xyz', 'aba', '1221']

Expected Result : 2

3) Write Python programs to


- Enter the list containing numbers
- Check if a list is empty
- Remove duplicates from a list
- Clone a list
- Find words longer than a given length from a list of words.
4) Write a Python program to:
- Convert a string to a list.
- Calculate the difference between the two lists
- Append a list to the second list and sort this new list
- Check if all items in a given list of strings are equal to a given string
- Insert a given string at the beginning of all items in a list.

Sample list : [1,2,3,4], string : emp

Expected output : ['emp1', 'emp2', 'emp3', 'emp4'


- Find items starting with a specific character from a list.

Example:

Original list: ['abcd', 'abc', 'bcd', 'bkie', 'cder', 'cdsw', 'sdfsd', 'dagfa', 'acjd']

Items start with a from the said list: ['abcd', 'abc', 'acjd']

Items start with d from the said list: ['dagfa']

Items start with w from the said list: []

5) Write a Python program to combine two lists into a dictionary. The elements of the
first one serve as keys and the elements of the second one serve as values. Each item
in the first list must be unique and hashable.

Example:

Original lists:

['a', 'b', 'c', 'd', 'e', 'f']

[1, 2, 3, 4, 5]

Combine the values of the said two lists into a dictionary:

{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}

You might also like