ASSIGNMENT - 2 , GO_STP_8113
GO_STP_8113
ASSIGNMENT -2
#OnlineSummerTraining #machinelearning #datascience #PYTHONNUMPY #pandas #pythonprogramming #goeduhub
Is a list mutable?
Does a list need to be homogeneous?
What is the difference between a list and a tuple.
- How to find the number of elements in the list?
- How to check whether the list is empty or not?
- How to find the first and last element of the list?
- How to find the largest and lowest value in the list?
max(ls)#lowest value
- How to access elements of the list?
Remove elements in a list before a specific index
Remove elements in a list between 2 indices
ls=[1,2,3,4,5]
del ls[1:4]
Return every 2nd element in a list between 2 indices
ls = [1,2,3]
print(ls[::2])
Get the first element from each nested list in a list
for i in ls:
print((i[0]))
- How to modify elements of the list?
- How to concatenate two lists?
- How to add two lists element-wise in python?
list2 = [4, 5, 6]
sum_list = [] .
for (item1, item2) in zip(list1, list2):
sum_list. append(item1+item2)
print(sum_list) [(1 + 4), (2 + 5), (3 + 6)]
- Difference between del and clear?
- Difference between remove and pop?
- Difference between append and extend?
- Difference between indexing and Slicing?
- Difference between sort and sorted?
- Difference between reverse and reversed?
- Difference between copy and deepcopy?
- How to remove duplicate elements in the list?
mylist = list(dict.fromkeys(mylist))
print(mylist)
- How to find an index of an element in the python list?
- How to find the occurrences of an element in the python list?
- How to insert an item at a given position?
- How to check if an item is in the list?
- How to flatten a list in python?
We can flatten a list in python using sum().
- How to convert python list to other data structures like set, tuple, dictionary?
tuple(list_name) #list to tuple
set(list_name) #list to set
To convert list to dictionary using dictionary comprehension.
- How to apply a function to all items in the list?
map() is used to apply a function to all items in the list
- How to filter the elements based on a function in a python list?
The filter() function iterates over the elements of the list and applies the fn() function to each element.
- How python lists are stored in memory?
Python has the variable refer to the value. Python keeps an internal counter on how many references an object has.
Comments
Post a Comment