Python - List Functions

List Functions


Often used in conditional statements, all and any take a list as an argument, and return True if all or any (respectively) of their arguments evaluate to True (and False otherwise). 
The function enumerate can be used to iterate through the values and indices of a list simultaneously.
Example:
nums = [55, 44, 33, 22, 11]

if all([i > 5 for i in nums]):
print("All larger than 5")

if any([i % 2 == 0 for i in nums]):
print("At least one is even")

for v in enumerate(nums):
print(v)
Result:>>>
All larger than 5
At least one is even
(0, 55)
(1, 44)
(2, 33)
(3, 22)
(4, 11)
>>>



List.append - to append to list

list.pop  --- to remove an element at the location which is provided as a parameter from the list.

list.remove  -- to remove an element using a value





Comments

Popular posts from this blog

Python - Argument Passing

Python - How to Escape special characters in String