SlideShare ist ein Scribd-Unternehmen logo
1 von 59
Downloaden Sie, um offline zu lesen
 Creating List
 Access, Modify and Delete list Elements
 Merge Lists
 Use the slicing syntax to operate on
sublists
 Loop over lists
 A list is a compound data type, you can group values
together
 A list contains items separated by commas and enclosed
within square brackets ([]).
 Lists are similar to arrays in C.
 One difference between them is that the items belonging
to a list can be of different data type.
 The values stored in a list can be accessed using the [ ]
operator
 Index starts at 0.
 What is the result of this code?
nums = [5, 4, 3, 2, 1]
print(nums[-2])
>>> math = 45
>>> science = 23
>>> social = 28
>>> marksList = [math, science, social]
>>>
>>> print(marksList)
[45, 23, 28]
 Create a list, areas, that contains the area of the hallway (hall), kitchen
(kit), living room (liv), bedroom (bed) and bathroom (bath), in this order.
Use the predefined variables.
 Print areas with the print() function.
# area variables (in square meters)
hall = 11.25
kit = 18.0
liv = 20.0
bed = 10.75
bath = 9.50
# Create list areas
_____________________________
# Print areas
_____________________________
SN Function with Description
1 len(list)
Gives the total length of the list.
2 max(list)
Returns item from the list with max value.
3 min(list)
Returns item from the list with min value.
4. sum(list)
Returns the sum of all elements of list
 Two List can be combined using +
operator.
 We cannot add a integer with list using +
 Forming new lists with a repeating sequence using the
multiplication operator:
 Create a list of 5 elements with initial value as 0
Insertion
Append(ele) Add element at end of List
Insert(index , ele) Add element at given index
Extend( seq ) Appends all the elements of seq to list
Deletion Pop(index) Delete element based on Index
Remove(key) Delete element based on key
Count(key) Returns the number of occurrences of key
Index(key) Returns the index of key element
Sort Sorts elements of List
Reverse Reverses elements of list
 We can add elements to list.
 To add one element, use append method.
 This adds an item to the end of an existing list.
mylist = []
mylist.append(5)
mylist.append(8)
mylist.append(12)
#prints [5,8,12]
print(mylist)
insert(index, element)
 Insert the elements in sorted order.
 Algorithm
 If list is empty, append element to list.
 If element is less than first element, insert front.
 Traverse till current element is less than
element to insert or till end of list
 Insert the element.
 We can add a series of elements using extend
method or + operator.
 a = [1,2,3]
 b = [4,5,6]
 Understand the difference between
 a.append(b) and
 a.extend(b)
 To delete last element
 To delete element at specific Index
 Remove method takes the key element to
delete and removes it if present.
 In all the previous methods, we were not able
to determine the index where the key
element is present.
 index() method finds the given element in
a list and returns its position.
 If the same element is present more than
once, index() method returns its
smallest/first position.
 If not found, it raises
a ValueError exception indicating the
element is not in the list.
 The index method finds the first occurrence of a list item and
returns its index.
If the item isn't in the list, it raises aValueError.
 letters = ['p', 'q', 'r', 's', 'p', 'u']
 print(letters.index('r'))
 print(letters.index('p'))
 print(letters.index('z'))
2
0
ValueError: 'z' is not in list
 The sort method can be used to sort the
elements of list.
 mylist = [5 , 8 , 12 , 20 , 25, 50]
 mylist[startIndex : endIndex]
 Mylist[startIndex : endIndex : step]
 mylist = [5 , 8 , 12 , 20 , 25, 50]
 print('Full list elements' , mylist)
 print('printing alternate elements', mylist[ : : 2])
 print('printing in reverse order ', mylist[ : : -1])
 == operator is used to check if two list have
same elements.
 is operator is used to check if two references
refer to same list.
 # area variables (in square meters)
 hall = 11.25
 kit = 18.0
 liv = 20.0
 bed = 10.75
 bath = 9.50
 # house information as list of lists
 house = [["hallway", hall],
 ["kitchen", kit],
 ["living room", liv],
 ["bedroom",bed],
 ["bathroom",bath]]
 # Print out house
 print(house)
 print(house[0])
 print(house[1][0]) [['hallway', 11.25], ['kitchen', 18.0], ['living room', 20.0], ['bedroom', 10.75], ['bathroom', 9.5]]
['hallway', 11.25]
kitchen
 BMI = weight/height2
 height = [ 1.87, 1.87, 1.82, 1.91, 1.90, 1.85]
 weight = [81.65, 97.52, 95.25, 92.98, 86.18, 88.45]
 bmi = weight / (height ** 2)
 BMI = weight/height2
 height = [ 1.87, 1.87, 1.82, 1.91, 1.90, 1.85]
 weight = [81.65, 97.52, 95.25, 92.98, 86.18, 88.45]
 bmi = []
 n = len(height)
 for i in range(0,n):
 bmi.append(weight[i] / (height[i] ** 2))
 print (bmi)
 Python List
 Convert a list of temperature values from
celsius to fahrenheit
 Given a list of elements, create a new list which
has elements with one added to every element
of old list.
 nums = [12, 8, 21, 3, 16]
 new_nums = [13, 9, 22, 4, 17]
 Collapse for loops for building lists into a
single line
 Components
 Iterable
 Iterator variable
 Output expression
 Given a list of elements extract all the odd
elements and place in new list.
 Conditionals on the iterable
 [num ** 2 for num in range(10) if num % 2 == 0]
 Conditionals on the output expression
 [num ** 2 if num % 2 == 0 else 0 for num in
range(10)]
 The all() function returns True if all elements of the
supplied iterable are true or if there are no elements.
 So if all elements in a list, tuple, or set match Python's
definition of being true, then all() returns True.
 The any() function is the converse of
the all() function. any() returns True if any element of
the iterable evaluates true.
 If the iterable is empty, the function returns False
 Read the marks of subject and find the result.
 Print Pass if marks scored in all the subjects is
>= 35 otherwise Fail.
The zip() function take iterables, makes iterator that aggregates elements
based on the iterables passed, and returns an iterator of tuples.

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Chapter 15 Lists
Chapter 15 ListsChapter 15 Lists
Chapter 15 Lists
 
Python variables and data types.pptx
Python variables and data types.pptxPython variables and data types.pptx
Python variables and data types.pptx
 
Tuples in Python
Tuples in PythonTuples in Python
Tuples in Python
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Unit 4 python -list methods
Unit 4   python -list methodsUnit 4   python -list methods
Unit 4 python -list methods
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
List in Python
List in PythonList in Python
List in Python
 
Python : Functions
Python : FunctionsPython : Functions
Python : Functions
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Python for loop
Python for loopPython for loop
Python for loop
 
Python list
Python listPython list
Python list
 

Ähnlich wie Python list

Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfMCCMOTOR
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptxSakith1
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdfAshaWankar1
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptxChandanVatsa2
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of DataIHTMINSTITUTE
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09Terry Yoast
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202Mahmoud Samir Fayed
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptxYagna15
 
Given a list of numbers- count and return how many pairs there are- A.docx
Given a list of numbers- count and return how many pairs there are- A.docxGiven a list of numbers- count and return how many pairs there are- A.docx
Given a list of numbers- count and return how many pairs there are- A.docxrtodd751
 
The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210Mahmoud Samir Fayed
 
List Data Structure.docx
List Data Structure.docxList Data Structure.docx
List Data Structure.docxmanohar25689
 
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAmuthachenthiruK
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in pythonCeline George
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189Mahmoud Samir Fayed
 

Ähnlich wie Python list (20)

Python lists & sets
Python lists & setsPython lists & sets
Python lists & sets
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
 
Lecture2.pptx
Lecture2.pptxLecture2.pptx
Lecture2.pptx
 
python_avw - Unit-03.pdf
python_avw - Unit-03.pdfpython_avw - Unit-03.pdf
python_avw - Unit-03.pdf
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
List_tuple_dictionary.pptx
List_tuple_dictionary.pptxList_tuple_dictionary.pptx
List_tuple_dictionary.pptx
 
Python PCEP Lists Collections of Data
Python PCEP Lists Collections of DataPython PCEP Lists Collections of Data
Python PCEP Lists Collections of Data
 
Module-2.pptx
Module-2.pptxModule-2.pptx
Module-2.pptx
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202The Ring programming language version 1.8 book - Part 27 of 202
The Ring programming language version 1.8 book - Part 27 of 202
 
Lists.pptx
Lists.pptxLists.pptx
Lists.pptx
 
Given a list of numbers- count and return how many pairs there are- A.docx
Given a list of numbers- count and return how many pairs there are- A.docxGiven a list of numbers- count and return how many pairs there are- A.docx
Given a list of numbers- count and return how many pairs there are- A.docx
 
The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210The Ring programming language version 1.9 book - Part 29 of 210
The Ring programming language version 1.9 book - Part 29 of 210
 
List Data Structure.docx
List Data Structure.docxList Data Structure.docx
List Data Structure.docx
 
Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
Chap09
Chap09Chap09
Chap09
 
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
 
Basic data structures in python
Basic data structures in pythonBasic data structures in python
Basic data structures in python
 
The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189The Ring programming language version 1.6 book - Part 24 of 189
The Ring programming language version 1.6 book - Part 24 of 189
 
Merge radix-sort-algorithm
Merge radix-sort-algorithmMerge radix-sort-algorithm
Merge radix-sort-algorithm
 

Mehr von Mohammed Sikander (18)

Operator Overloading in C++
Operator Overloading in C++Operator Overloading in C++
Operator Overloading in C++
 
Python_Regular Expression
Python_Regular ExpressionPython_Regular Expression
Python_Regular Expression
 
Modern_CPP-Range-Based For Loop.pptx
Modern_CPP-Range-Based For Loop.pptxModern_CPP-Range-Based For Loop.pptx
Modern_CPP-Range-Based For Loop.pptx
 
Modern_cpp_auto.pdf
Modern_cpp_auto.pdfModern_cpp_auto.pdf
Modern_cpp_auto.pdf
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Python strings
Python stringsPython strings
Python strings
 
Python Flow Control
Python Flow ControlPython Flow Control
Python Flow Control
 
Introduction to Python
Introduction to Python  Introduction to Python
Introduction to Python
 
Pointer basics
Pointer basicsPointer basics
Pointer basics
 
Signal
SignalSignal
Signal
 
File management
File managementFile management
File management
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
CPP Language Basics - Reference
CPP Language Basics - ReferenceCPP Language Basics - Reference
CPP Language Basics - Reference
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
Java strings
Java   stringsJava   strings
Java strings
 
Java notes 1 - operators control-flow
Java notes   1 - operators control-flowJava notes   1 - operators control-flow
Java notes 1 - operators control-flow
 
Questions typedef and macros
Questions typedef and macrosQuestions typedef and macros
Questions typedef and macros
 
Pointer level 2
Pointer   level 2Pointer   level 2
Pointer level 2
 

Kürzlich hochgeladen

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...masabamasaba
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...masabamasaba
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrandmasabamasaba
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...SelfMade bd
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyviewmasabamasaba
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareJim McKeeth
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfonteinmasabamasaba
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
tonesoftg
tonesoftgtonesoftg
tonesoftglanshi9
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...masabamasaba
 

Kürzlich hochgeladen (20)

%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
WSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaSWSO2CON 2024 Slides - Open Source to SaaS
WSO2CON 2024 Slides - Open Source to SaaS
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
%in Hazyview+277-882-255-28 abortion pills for sale in Hazyview
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
WSO2CON 2024 - Navigating API Complexity: REST, GraphQL, gRPC, Websocket, Web...
 
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
WSO2CON 2024 - Building the API First Enterprise – Running an API Program, fr...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
tonesoftg
tonesoftgtonesoftg
tonesoftg
 
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
WSO2CON 2024 - WSO2's Digital Transformation Journey with Choreo: A Platforml...
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 

Python list

  • 1.
  • 2.  Creating List  Access, Modify and Delete list Elements  Merge Lists  Use the slicing syntax to operate on sublists  Loop over lists
  • 3.  A list is a compound data type, you can group values together  A list contains items separated by commas and enclosed within square brackets ([]).  Lists are similar to arrays in C.  One difference between them is that the items belonging to a list can be of different data type.  The values stored in a list can be accessed using the [ ] operator  Index starts at 0.
  • 4.
  • 5.
  • 6.  What is the result of this code? nums = [5, 4, 3, 2, 1] print(nums[-2])
  • 7. >>> math = 45 >>> science = 23 >>> social = 28 >>> marksList = [math, science, social] >>> >>> print(marksList) [45, 23, 28]
  • 8.  Create a list, areas, that contains the area of the hallway (hall), kitchen (kit), living room (liv), bedroom (bed) and bathroom (bath), in this order. Use the predefined variables.  Print areas with the print() function. # area variables (in square meters) hall = 11.25 kit = 18.0 liv = 20.0 bed = 10.75 bath = 9.50 # Create list areas _____________________________ # Print areas _____________________________
  • 9. SN Function with Description 1 len(list) Gives the total length of the list. 2 max(list) Returns item from the list with max value. 3 min(list) Returns item from the list with min value. 4. sum(list) Returns the sum of all elements of list
  • 10.
  • 11.
  • 12.  Two List can be combined using + operator.  We cannot add a integer with list using +
  • 13.  Forming new lists with a repeating sequence using the multiplication operator:  Create a list of 5 elements with initial value as 0
  • 14. Insertion Append(ele) Add element at end of List Insert(index , ele) Add element at given index Extend( seq ) Appends all the elements of seq to list Deletion Pop(index) Delete element based on Index Remove(key) Delete element based on key Count(key) Returns the number of occurrences of key Index(key) Returns the index of key element Sort Sorts elements of List Reverse Reverses elements of list
  • 15.  We can add elements to list.  To add one element, use append method.  This adds an item to the end of an existing list. mylist = [] mylist.append(5) mylist.append(8) mylist.append(12) #prints [5,8,12] print(mylist)
  • 16.
  • 18.  Insert the elements in sorted order.  Algorithm  If list is empty, append element to list.  If element is less than first element, insert front.  Traverse till current element is less than element to insert or till end of list  Insert the element.
  • 19.  We can add a series of elements using extend method or + operator.
  • 20.  a = [1,2,3]  b = [4,5,6]  Understand the difference between  a.append(b) and  a.extend(b)
  • 21.  To delete last element
  • 22.  To delete element at specific Index
  • 23.  Remove method takes the key element to delete and removes it if present.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.  In all the previous methods, we were not able to determine the index where the key element is present.
  • 30.  index() method finds the given element in a list and returns its position.  If the same element is present more than once, index() method returns its smallest/first position.  If not found, it raises a ValueError exception indicating the element is not in the list.
  • 31.  The index method finds the first occurrence of a list item and returns its index. If the item isn't in the list, it raises aValueError.  letters = ['p', 'q', 'r', 's', 'p', 'u']  print(letters.index('r'))  print(letters.index('p'))  print(letters.index('z')) 2 0 ValueError: 'z' is not in list
  • 32.
  • 33.
  • 34.  The sort method can be used to sort the elements of list.
  • 35.
  • 36.
  • 37.
  • 38.  mylist = [5 , 8 , 12 , 20 , 25, 50]  mylist[startIndex : endIndex]
  • 39.
  • 40.  Mylist[startIndex : endIndex : step]  mylist = [5 , 8 , 12 , 20 , 25, 50]  print('Full list elements' , mylist)  print('printing alternate elements', mylist[ : : 2])  print('printing in reverse order ', mylist[ : : -1])
  • 41.
  • 42.  == operator is used to check if two list have same elements.  is operator is used to check if two references refer to same list.
  • 43.
  • 44.
  • 45.  # area variables (in square meters)  hall = 11.25  kit = 18.0  liv = 20.0  bed = 10.75  bath = 9.50  # house information as list of lists  house = [["hallway", hall],  ["kitchen", kit],  ["living room", liv],  ["bedroom",bed],  ["bathroom",bath]]  # Print out house  print(house)  print(house[0])  print(house[1][0]) [['hallway', 11.25], ['kitchen', 18.0], ['living room', 20.0], ['bedroom', 10.75], ['bathroom', 9.5]] ['hallway', 11.25] kitchen
  • 46.  BMI = weight/height2  height = [ 1.87, 1.87, 1.82, 1.91, 1.90, 1.85]  weight = [81.65, 97.52, 95.25, 92.98, 86.18, 88.45]  bmi = weight / (height ** 2)
  • 47.  BMI = weight/height2  height = [ 1.87, 1.87, 1.82, 1.91, 1.90, 1.85]  weight = [81.65, 97.52, 95.25, 92.98, 86.18, 88.45]  bmi = []  n = len(height)  for i in range(0,n):  bmi.append(weight[i] / (height[i] ** 2))  print (bmi)
  • 48.  Python List  Convert a list of temperature values from celsius to fahrenheit
  • 49.  Given a list of elements, create a new list which has elements with one added to every element of old list.  nums = [12, 8, 21, 3, 16]  new_nums = [13, 9, 22, 4, 17]
  • 50.  Collapse for loops for building lists into a single line  Components  Iterable  Iterator variable  Output expression
  • 51.
  • 52.
  • 53.  Given a list of elements extract all the odd elements and place in new list.
  • 54.
  • 55.  Conditionals on the iterable  [num ** 2 for num in range(10) if num % 2 == 0]  Conditionals on the output expression  [num ** 2 if num % 2 == 0 else 0 for num in range(10)]
  • 56.  The all() function returns True if all elements of the supplied iterable are true or if there are no elements.  So if all elements in a list, tuple, or set match Python's definition of being true, then all() returns True.
  • 57.  The any() function is the converse of the all() function. any() returns True if any element of the iterable evaluates true.  If the iterable is empty, the function returns False
  • 58.  Read the marks of subject and find the result.  Print Pass if marks scored in all the subjects is >= 35 otherwise Fail.
  • 59. The zip() function take iterables, makes iterator that aggregates elements based on the iterables passed, and returns an iterator of tuples.