Archive Pages Design$type=blogging

Python List Comprehension


Python List ComprehensionPython supports a concept called "list comprehensions". It can be used to construct lists in a very natural, easy way, like a mathematician is used to do.

List comprehension is an elegant way to define and create list in Python. These lists have often the qualities of sets, but are not in all cases sets.


The following list comprehension function converts Celsius values into Fahrenheit and vice versa :-

>>> Celsius = [39.2, 36.5, 37.3, 37.8]
>>> Fahrenheit = [ ((float(9)/5)*x + 32) for x in Celsius ]
>>> print Fahrenheit
>>> [102.56, 97.700000000000003, 99.140000000000001, 100.03999999999999]

advance algorithms analytics basic comprehension data analysis data mining data science data structure ebook google interview latest online learning overview python yield
Python Faq: Python List Comprehension
Python List Comprehension
python list comprehension example python list comprehension filter python list comprehension multiple if python list comprehension nested loop python list comprehension if python list comprehension multiple for loops python list comprehension faster than for loop python list comprehension lambda
Python Faq
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago