My QA Projects

QA Projects I was involded.

View on GitHub

Comprehension

Comprehension restrictions

Comparison

mylist = []
for item in iterable:
    mylist.appen(exp)

# and now the comprehension way

mylist = [exp for item in iterable]

List Comprehension Example

numbers = [1, 2, 3, 4, 5]
squared_numbers = [x ** 2 for x in numbers]

print(squared_numbers)  # Output: [1, 4, 9, 16, 25]

List Comprehension other types

numbers = [1, 2, 3, 4, 5]
# Dictionary Comprehension: Creating a dictionary of squares
squared_dict = {x: x ** 2 for x in numbers}
print(squared_dict)  # Output: {1: 1, 2: 4, 3: 9, 4: 16, 5: 25}
# Set Comprehension: Creating a set of squares
numbers = [1, 2, 3, 4, 5, 5]  # Note: 5 is repeated
squared_set = {x ** 2 for x in numbers}
print(squared_set)  # Output: {1, 4, 9, 16, 25}

Comprehension with Conditional

mylist = []
for item in iterable:
    if cond_exp:
        mylist.appen(exp)

mylist = [exp for item in iterable if cond_exp]

List Comprehension Example 2

cities = ['Albany', 'berkeley','corte madera','Daly City']
bac = [city.upper() for city in cities]
# comprehension has the square brakets, indicate it is a list
# for city in cities: iterate through the items in the cities list
# expression: city.upper
print(bac)
cities = ['Albany', 'berkeley','corte madera','Daly City']
bac = [city.upper() for city in cities if len(city.split()) > 1]
print(bac)