List and Tuples
Lists: list operations, list slices, list methods, list loop, mutability, aliasing, cloning lists, list parameters;
Tuples: tuple assignment, tuple as return value; Dictionaries: operations and methods; advanced list processing - list comprehension; Illustrative programs: selection sort, insertion sort, merge sort, histogram.
LIST
Definition List is a structure datatype of python that is collection of sequence of values belonging of any type.List we depicted through source structure []. Lists are mutable: (i.e.) modifiable: you can change the elements of list at any time you want.
CREATING A LIST
To create a list, add a number of expressions, separated by comma within a square bracket.
Syntax: var_name=[element1,element2,…..element n]
Example: List1=[] #empty list List2=[1,2,3] #list with values of same type List3=[1, “a”,2,”s”,3,”red”,4] #list with values of different types
Example for creating list with for loop list=[] print(“Enter 10 no:”) fori in range (10): list.append(eval(input())
LIST VS STRING
Listsand strings have many similarities and differences.
Similarities between lists and strings
List and string use same function as • length: len(variable_name) • indexing: L[i] • slicing: L[initial,end,step value] • membership operator: in & not in • concatenation and replication operators:[+ - concatenate, * - from replication] • Accessing individual elements: L[index]
Differences between list and string
• Mutability: String is immutable but list is mutable. • Storage: Listis stored in memory exactly like string, except that the objects are larger than others.
Index operators []:
Syntax:list_variable[index] 