logotransparent.png

Legion of Learners

www.lol-101.com

  • Home

  • Classrooms

  • Courses

  • About Us

    • Executive Team
    • Board Members
  • Resources

  • More

    Use tab to navigate through the menu items.
    To see this working, head to your live site.
    • Categories
    • All Posts
    • My Posts
    sfolax6776
    Jan 24, 2021

    A quick review of sets and lists

    in Introduction to Python

    A. Introduction

    Now you know what sets and lists are, you can learn more about them! Try the following tasks and if you get stuck, feel free to check out more about sets and lists to find the tools you need to solve problems.

    B. Try these problems and see how many you can solve.

    1. Given two lists of numbers, count how many numbers of the first one occur in the second one.

    2. Given two lists of numbers, find all the numbers that occur in both the first and the second list. Print them in ascending order.

    3. Given a list of numbers, find and print all its elements that are greater than their left neighbor.

    4. Given a list of non-zero integers, find and print the first adjacent pair of elements that have the same sign. If there is no such pair, print 0.

    8 comments
    0
    albertwwyy
    Jan 24, 2021

    Do we have to write it here??

    0
    Steven
    Jan 24, 2021

    Yes, please do!

    0
    justannie2019
    Jan 24, 2021  ·  Edited: Jan 24, 2021

    How many elements should we include in the list in homework 3, also why is there no homework including sets?

    0
    Steven
    Jan 24, 2021

    The number of elements in the list does not matter too much, you can use a relatively short list of 5-10 elements for this problem.

    0
    RZ97500
    Jan 24, 2021

    How is the union method used? I think that's the solution to one of the problems.

    0
    Steven
    Jan 24, 2021

    There are lots of resources on the internet about the methods - try Googling "python set union method" and taking a look at what comes up!

    0
    kyleboss220
    Jan 24, 2021

    2. numbers = [1, 3, 4, 2,6,4,43,6,3] numbers2= [1,6,3,5,67,4,6,3] for x in numbers2: numbers.append(x) numbers.sort(reverse = True) print(numbers)

    0
    luphy.ma
    Jan 29, 2021

    #Task 1 l1 = [60,7,4,74] l2 = [42,67,7,74] oekl = list((set(l1).intersection(set(l2)))) print("Task 1: \n") ok = len(oekl) print(ok) #Task 2 ll1 = [60,7,4,74] ll2 = [42,67,7,74] okl = list((set(ll1).intersection(set(ll2)))) print("\nTask 2: \n") print(okl) #Task 3 lll1 = [60,7,4,74] print("\nTask 3: \n") beep = lll1[0] for i in lll1: if i > beep: print(i) beep = i #Task 4 llll1 = [60,7,-4,74] beepy = 0 finish = [] for i in llll1: if i > 0 and beepy > 0: finish.append(beepy) finish.append(i) if i < 0 and beepy < 0: finish.append(beepy) finish.append(i) beepy = i finish1 = finish[0] finish2 = finish[1] print("\nTask 4:\n") print(finish1, finish2)

    0
    8 comments

    Questions? Email us at legionoflearners@gmail.com or join our WeChat group!

    • lol-101dotcom

    ©2020 Legion of Learners