Home | | Problem Solving and Python Programming | Advanced list processing - Python

Chapter: Problem Solving and Python Programming : Lists, Tuples, Dictionaries

Advanced list processing - Python

List comprehensions provide a concise way to apply operations on a list.

Advanced list processing:

List Comprehension:

v       List comprehensions provide a concise way to apply operations on a list.

v       It creates a new list in which each element is the result of applying a given operation in a list.

v       It consists of brackets containing an expression followed by a “for” clause, then a list.

v       The list comprehension always returns a result list.

 

Syntax

list=[ expression for item in list if conditional ]




Nested list:

List inside another list is called nested list.

 

Example:

>>> a=[56,34,5,[34,57]]

>>> a[0]

 

56

>>> a[3]

[34, 57]

>>> a[3][0]

34

>>> a[3][1]

57

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Problem Solving and Python Programming : Lists, Tuples, Dictionaries : Advanced list processing - Python |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.