List Manupulation
List Manupulation
List Manupulation
By-
Neha Tyagi
PGT CS
KV 5 Jaipur II Shift, Jaipur Region
• A List is a mutable data type which means any value from the
list can be changed. For changed values , Python does not
create a new list.
• Long lists-
This is tuple
even = [0, 2, 4, 6, 8, 10 ,12 ,14 ,16 ,18 ,20 ]
• Nested list -
L = [ 3, 4, [ 5, 6 ], 7]
Another method
eval ( ) function identifies type of the passed string and then return it.
Another example
String Values
Important 2: + operator
adds a list at the end of
other list whereas *
operator repeats a list.
Value didn’t
change in string.
Error shown. Value got changed
in list specifying
list is mutable
Some
examples
Last item
6th item
1st item
List.extend(<list>) Append the list (passed in the form of argument) at the end of list
with which function is called.
List.pop(<index>) Delete and return the element of passed index. Index passing is
optional, if not passed, element from last will be deleted.
List.remove(<value>) It will delete the first occurrence of passed value but does not
return the deleted value.
List.clear ( ) It will delete all values of list and gives an empty list.
List.count (<item>) It will count and return number of occurrences of the passed element.
List.reverse ( ) It will reverse the list and it does not create a new list.
List.sort ( ) It will sort the list in ascending order. To sort the list in descending
order, we need to write----- list.sort(reverse =True).
• List.append( ) function:
• List.extend( ) function:
• List.insert( ) function:
• List.remove( ) function:
• List.count( ) function:
• List.sort( ) function:
Important
• To sort a list in reverse order, write in following manner–
List.sort(reverse=True)
www.pythontrends.wordpress.com
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: