Please enable JavaScript.
Coggle requires JavaScript to display documents.
LISTS IN PYTHON: - Coggle Diagram
LISTS IN PYTHON:
built in functions
-
-
-
reverse it reverses the order of the elements in a list it replaces the new value in place of an item that already exists in a list
-
insert: add a specfic element at a specfied index insert(index number,value)
-
-
-
operation on lists
-
-
memebership testing: to test wether an element is a part of list using in or not in operator in with for loop it can be used to print list of all elements in a list
-
-
-
deletition operation
-
-
pop() it removes the element from the specified index and also returns the element which was removed
-
traversing a list: it means acessing each element of a list it can be done using for or while loop statements
using range() function it can be used to tell the characters in a string by defining len() as no of characters
using while loop the list of elements can also be acessed using while loop firstly use len() to tell the length then while loop starts from index 0 and iterated through list of items by refering to their indexes
using in operator inside for loop
list= [a,c,b,n]
for i in list:
print(i)
here i will be assignes the first value of the list till last one by one
it is a collection of values or an ordered sequence of values/items , they are enclosed under [] square brackets seprated by commas they are mutable
the () list method in python takes sequence types and converts a given record/tuple or string into list
types of lists:
empty lists
long lists
nested lists
how to make lists:
1 an empty listis created with built in function list()
2 creating a list from a sequence (string)
3 creating a list through user input using list()
4 creating a list from an existing list by using list(x:y) x= start value and y=n+1 value
sorting
bubble sort: simplest sorting technique to transverse the whole list by comparing its adjacent elements until whole list is sorted
insertion sort: it starts from index1 not 0 and each index starting from index 1 is like a new report card that you have to place at the proper position in the sorted sub array on the left
acessing list elements(indexing)
the list index starts from 0 and go to length -1 each element can be acessed by using their indexes enclosed inside square brackets
aliasing: bsically changing elements at specfic index by make another list with all the same elements except the ones you want to change and keeping the name of this new list equal to the old one
-
nested lists: when a list appears as an element in another list and to acess a nested list we need to specify two indexes list1[i][j] first i will tell the nested list and the second index [j] gives the element in the nested list