Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python dictionary comprehension

users = {'sam': 20, 'mike': 30, 'joe': 40}

# return users where the ave is greater than 20
users_over_20 = {k: v for k, v in users.items() if v > 20}

# print users over 20
print(users_over_20)
# output {'mike': 30, 'joe': 40}
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #python #dictionary #comprehension
ADD COMMENT
Topic
Name
7+9 =