Lists & Tuples
Lists & Tuples
LISTS
• List2 & List3 are nested liststhey have another list as an element
• [] null list
CREATE LISTS USING range( ) & list ( )
FUNCTIONS
• list1=list(range(10)) list1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
• list2=list(range(1,10)) list2=[1, 2, 3, 4, 5, 6, 7, 8, 9]
• list3=list(range(1,14,3)) list3=[1, 4, 7, 10, 13]
FINDING LIST OF A STRING len()
FUNCTION
program
List1=[1,3,5,7]
Print(len(List1))
Output
4
ACCESSING ELEMENTS OF A LIST
Students=['Gowri','Grace','Grushab','Hamda
n']
for x in Students:
print(x)
LIST COMPREHENSION
Students=['Gowri','Grace','Grushab','Hamdan']
Gstudents=[x for x in Students if x[0]=='G']
print(Gstudents)
+ CONCATANATION
* REPEATS A LIST A GIVEN NUMBER OF TIMES
==CHECKS IF TWO LISTS HAVE THE SAME
ELEMENTS.
RELATIONAL OPERATORS
MEMBERSHIP
OPERATOR
USING
VARIABLES AS
ELEMENTS IN
LIST
LIST SLICES
LIST MUTATIONS