External Exam Download Resources Web Applications Games Recycle Bin

encryption basics 2

encryption_basics2.py

# an iterable in python is an object capable of
# returning its elements one at a time, via a loop:
digits = [0,1,2,3,4,5,6,7,8,9]
# ^ this is a Python list, it is iterable, and is
# also known as an array in other languages.

# a quicker way to make a list of digits from 0 to 9 inclusive:
digits = list(range(10))
print(digits)

# create a list of alphabet letters programatically:
alphabet_v1 = []
# loop through ordinals 65 ("A") through 90 ("Z"):
for i in range(65, 91):
    #range(start, stop, step=1)
    letter = chr(i)
    alphabet_v1.append(letter) #.append to join to list
print(alphabet_v1)

# map() applies function x to iterable y:
alphabet_v2 = list(map(chr, range(65, 91)))
print(alphabet_v2)

# enumerate() adds a counter (a.k.a. index, indice or position)
# to an iterable. note the first element in a list is element 0:
for position, element in enumerate(alphabet_v2):
    print("Position:", position, "Element:", element)