filmov
tv
Python Bytes: List Comprehensions Introduction

Показать описание
Python Bytes
Intermediate Python Topics
List Comprehensions Introduction
#A method of making lists from other values.
#Defining a list and its contents at the same time.
# new_list = [ item for item in iterable ]
#An 'iterable' is an object that contains other objects within it.
#Lists, Dictionaries, Tuples, Sets, range(), and more.
#You can work backwards from a loop to create the comprehension and understand the logic.
#This is a good technique when you are still new to list comprehensions.
#Example 1:
new_list = list()
for num in range(0,10):
new_list = [num for num in range(0,10)]
#Example 2:
hostnames = list()
for fqdn in fqdns:
Intermediate Python Topics
List Comprehensions Introduction
#A method of making lists from other values.
#Defining a list and its contents at the same time.
# new_list = [ item for item in iterable ]
#An 'iterable' is an object that contains other objects within it.
#Lists, Dictionaries, Tuples, Sets, range(), and more.
#You can work backwards from a loop to create the comprehension and understand the logic.
#This is a good technique when you are still new to list comprehensions.
#Example 1:
new_list = list()
for num in range(0,10):
new_list = [num for num in range(0,10)]
#Example 2:
hostnames = list()
for fqdn in fqdns: