Пример #1
0
def linq7():
    products = shared.getProductList()

    product_names = (p.ProductName for p in products)

    print("Product Names:")
    shared.printS(product_names)
Пример #2
0
def linq47():
    products = shared.getProductList()

    category_names = {p.Category for p in products}

    print("Category names:")
    shared.printS(category_names)
Пример #3
0
def linq28():
    words = ["cherry", "apple", "blueberry"]

    sorted_words = sorted(words)

    print("The sorted list of words:")
    shared.printS(sorted_words)
Пример #4
0
def linq29():
    words = ["cherry", "apple", "blueberry"]

    sorted_words = sorted(words, key=lambda x: len(x))

    print("The sorted list of words (by length):")
    shared.printS(sorted_words)
Пример #5
0
def linq38():
    words = ["aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry"]

    # two pass sort, sort by least significant first
    sorted_words = sorted(words,
                          key=lambda word: word.casefold(),
                          reverse=True)
    sorted_words = sorted(sorted_words, key=lambda word: len(word))

    shared.printS(sorted_words)
Пример #6
0
def linq35():
    digits = [
        "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
        "nine"
    ]

    sorted_digits = sorted(digits, key=lambda digit: (len(digit), digit))

    print("Sorted digits:")
    shared.printS(sorted_digits)
Пример #7
0
def linq53():
    products = shared.getProductList()
    customers = shared.getCustomerList()

    product_first_chars = {p.ProductName[0] for p in products}
    customer_first_chars = {c.CompanyName[0] for c in customers}

    unique_first_chars = product_first_chars.difference(customer_first_chars)

    print("First letters from Product names, but not from Customer names:")
    shared.printS(unique_first_chars)
Пример #8
0
def linq51():
    products = shared.getProductList()
    customers = shared.getCustomerList()

    product_first_chars = {p.ProductName[0] for p in products}
    customer_first_chars = {c.CompanyName[0] for c in customers}

    unique_first_chars = product_first_chars.intersection(customer_first_chars)

    print("Common first letters from Product names and Customer names:")
    shared.printS(unique_first_chars)
Пример #9
0
def linq13():
    numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
    digits = [
        "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
        "nine"
    ]

    result = (digits[n] for n in numbers if n < 5)

    print("Numbers < 5:")
    shared.printS(result)
Пример #10
0
def linq8():
    numbers = [5, 4, 1, 3, 9, 8, 6, 7, 2, 0]
    strings = [
        "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
        "nine"
    ]

    text_nums = (strings[n] for n in numbers)

    print("Number strings:")
    shared.printS(text_nums)
Пример #11
0
def linq39():
    digits = [
        "zero", "one", "two", "three", "four", "five", "six", "seven", "eight",
        "nine"
    ]

    reversed_i_digits = reversed(
        list(filter(lambda digit: digit[1] == "i", digits)))

    print("A backwards list of the digits with a second character of 'i':")
    shared.printS(reversed_i_digits)
Пример #12
0
def linq95():
    products = shared.getProductList()
    customers = shared.getCustomerList()

    customer_names = [p.ProductName for p in products]
    product_names = [c.CompanyName for c in customers]

    all_names = customer_names + product_names

    print("Customer and product names:")
    shared.printS(all_names)
Пример #13
0
def linq36():
    words = ["aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry"]

    sorted_words = sorted(words, key=lambda word: (len(word), word.casefold()))

    shared.printS(sorted_words)