Previous Lecture Lecture 1 Next Lecture

Lecture 1, Thu 04/03

Introduction, Python Review


Code Clarity

Data Structures: Set vs. List

# Sets vs lists

set1 = {1, 1, 1, 3}
list1 = [1, 1, 1, 3]

print(set1)
print(list1)
print(set(list1))

Autograder

Testing & Assertions

Design activity

An example of how to store weaknesses and vulnerabilities with their related attributes:

# Using a list to keep track of the weakness and the related counts
# [200, 45, 1 , 3] 

# Alternatively, using a nested dictionary
threat_database = {
    "CWE-20": {
        "pillar": 200,
        "base": 45,
        "class": 1,
        "variant": 3
        },
    "CWE-200": {
        "pillar": None,
        "base": None,
        "class": None,
        "variant": None
        }
    }

# Two ways to retrieve values
print(threat_database["CWE-200"]["variant"])
print(threat_database.get("CWE-20").get("variant")) # less prone to errors

iClicker notes

# The code from the iClicker question

cve_val = "CVE-2022-21668"
cwe_val = "CWE-400"
year = 2022

print(f'cve_val cwe_val year')
#print(f'{cve_val} '{cwe_val}' {(year)}' )