Created
October 23, 2017 15:42
-
-
Save Mikelew88/307209273f83060aae2f5b02d4d73787 to your computer and use it in GitHub Desktop.
Python 101 Blog Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# variable | |
var1 = 10 | |
# list | |
anything = [10, 10, 3, 2] | |
# dict | |
dict1 = {'apple': 'green', 'grape':'red', 'other grape':'green', 'apple':'red'} | |
# loops through lists | |
for index, element in enumerate(anything): | |
# My favorite method for inserting variables into strings | |
print("Element {0}: {1}".format(index, element)) | |
# another method for inserting into strings. | |
print("Element %i: %i" % (index, element)) | |
# through dicts | |
for key, val in dict1.iteritems(): | |
if val == 'green': | |
print(key + ' is ' + val) | |
# ex function 1 | |
def key_in_value(input_to_function): | |
""" | |
INPUT: dict | |
OUTPUT: list | |
Return the keys from the dictionary where the key is a member in the | |
associated value. | |
example: | |
INPUT: {"a": ["b", "c", "a"], "b": ["a", "c"], "c": ["c"]} | |
OUTPUT: ["a", "c"] | |
Hint: Use iteritems | |
(Can be done on one line with a list comprehension) | |
""" | |
pass | |
# call function | |
output = key_in_value({"a": ["b", "c", "a"], "b": ["a", "c"], "c": ["c"]}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment