python_wiki:list_comprehensions

This is an old revision of the document!


List Comprehensions

General Information

List comprehensions are a way to create lists based on lists.

They cut out a step in which you would create an intermediate list just to create a new list.

Checklist

  • Python 2 or 3

Usage

FIXME → Fill out list comprehension example and code.

Using the code snippet.

chmod +x list-comp.py
./list-comp.py
 
# Example output
('The tuple is: ', ('centos', 'ubuntu', 'fedora', 'windows', 'arch', 'freebsd'))
('The nix os list is: ', ['centos', 'ubuntu', 'fedora', 'arch', 'freebsd'])

The Code

program-name.py
Program code here

  • python_wiki/list_comprehensions.1533271920.txt.gz
  • Last modified: 2019/05/25 23:50
  • (external edit)