Questions on LIST in Python
Python All list methods
Declare one blank list and then add four items to it.
Solution
my_list=[]
my_list.append('Alex')
my_list.append('Ronn')
my_list.append('Geek')
my_list.append('Rabi')
Declare one list by using one integer , one float and two strings. After adding display 2nd element and check the data type of the list.
Solution
my_list=['Alex',4,'Ronn',6.54]
print(type(my_list))
print(my_list[2])
Create one list by using output of a range. Example : your list should have all the numbers starting from 5 to less than 50 with increment of 5.
Solution
x=range(5,50,10)
my_list=list(x)
print(my_list)
Display all items of a list by looping
Solution
my_list=[2,4,1,2,4,5,3]
for i in my_list:
print(i)
Display last item
Solution
my_list=[2,4,1,2,4,5,3]
print(my_list[-1])
Display 2nd item from last
Solution
my_list=[2,4,1,2,4,5,3]
print(my_list[-2])
All items starting from 0 till last
Solution
my_list=[2,4,1,2,4,5,3]
print(my_list[0:])
All items starting from 1 till last
Solution
my_list=[2,4,1,2,4,5,3]
print(my_list[1:])
All items starting from 2 to 4
Solution
my_list=[2,4,1,2,4,5,3]
print(my_list[2:4])
Create one list with names of your five friends. Return the position of your best friend in the list.
Add one name Alex to above list. ( append())
Add name ‘Ronn’ to 2nd position ( insert()).
Create two list and then merger 2nd list with first list and display the output ( extend() )
Create a copy of your friends list
Remove one element from the list ( specify the name )
Remove the 2nd element from the list and display the removed element ( use pop() )
Remove all the elements of a list.
Create a list using names of your friends, then search for your best friend name inside the list ( use in )
Find the total number of elements present in a list ( use len() )
Find the number of time one particular element is present inside (use count() )
Reverse the order of the list and then print
Sort a list then print
Create a list of your friends and sort them in the order of their length.
In above list reverse the sorting order
Create one list and remove duplicate elements from it.
Find the sum of all elements of a list with integers as elements.
Find the highest and lowest number of a list
What is the difference between append() and insert() methods?
What is the difference between append() and extend() methods?
Take one input string and create one list by using all the chars of the string.
In above list remove the duplicate chars
Find the common elements between two lists.
Python- Multi dimensional List »
Matrix Multiplication without using built-in functions
Python- List append »
← Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
plus2net.com