append to list number above and below

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newuser1096
    New Member
    • Mar 2019
    • 1

    append to list number above and below

    hello. I really need help with this assignment.
    the assignment is this:
    splitAround(num s, pivot), where nums is an arbitrary list of numbers, and pivot is an arbitrary integer.

    splitAround should return a dictionary, with two keys - "above" and "below". "below" should represent a list of values from nums, that are lesser than pivot, and "above" should represent a list values that are greater than pivot.

    For example:
    splitAround([5, 4, 10, 3], 4) => {"below": [3], "above": [5, 10]}

    I started writing something along the lines of
    y = {"above":[], "below":[]}

    def splitAround(num bers):
    y = []
    for x in numbers:
    if x > p:
    return ["above"]
    if x < p:
    return ["below"]
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    I'm not a python programmer meself but, I stored your code in a file name test.py:
    Code:
    python.exe c:\temp\test.py
      File "c:\temp\test.py", line 4
        y = []
        ^
    IndentationError: expected an indented block
    H'm this is a thing you should/could have have detected before posting here.

    If you do something like this:
    Code:
    a = [1,2,3]
    b = [4,5,6]
    c = [a,b]
    print(c)
    This returns: "[[1, 2, 3], [4, 5, 6]]"

    So, the first line(s) of your code should look like:
    Code:
    above = []
    below = []
    y = [above, below]
    When printing y after this it returns: "[[], []]"
    which seems to be more like you want it.

    Comment

    • Luuk
      Recognized Expert Top Contributor
      • Mar 2012
      • 1043

      #3
      and PLEASE, there is a toolbar above this section where you type your text..... It also has a '[CODE/]'-tag....

      I wonder why someone has invented that ….. 😊

      Comment

      Working...