Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

comprehensions

print([x * 2 for x in range(10) if x % 2 == 0])  # [0, 4, 8, 12, 16]
Comment

comprehension

# user data entered as name and phone number
user_data = "Elvis Presley 987-654-3210"
phone_number = [ x for x in user_data if x.isdigit()]

print(phone_number)
Comment

comprehension

# open the file in read-only mode
file = open("dreams.txt", 'r')
poem = [ line for line in file ]

for line in poem:
    print(line)
Comment

PREVIOUS NEXT
Code Example
Python :: what is proc file 
Python :: python zip function 
Python :: python image resize 
Python :: numpy split to chunks of equal size 
Python :: <ipython-input-31-da456dc89cda in <module 
Python :: missing number 
Python :: obspy stats 
Python :: Compute Jordan normal form of matrix in Python / NumPy 
Python :: django graphene without model 
Python :: pybind11 python37_d.dll access violation 
Python :: reading a cell from another cell in colab 
Python :: exit from python manage py createsuperuser 
Python :: how to detect the body with cv2 
Python :: pytest using tempfile 
Python :: matplotlib show two distinct plots 
Python :: assertRaises property 
Python :: select features and label from df 
Python :: python average function program 
Python :: print the list item dtype 
Python :: .all() python numpy 
Python :: pytorch argmax 
Python :: yahoo finance python chart 
Python :: remove nan from list 
Python :: how to create a window in pygame 
Python :: pandas 
Python :: pandas sample 
Python :: rotate 2 dimensional list python 
Python :: how to use loop in python 
Python :: resampling data python 
Python :: run python from c# 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =