By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,008 Members | 2,895 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,008 IT Pros & Developers. It's quick & easy.

append to list number above and below

P: 1
hello. I really need help with this assignment.
the assignment is this:
splitAround(nums, 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(numbers):
y = []
for x in numbers:
if x > p:
return ["above"]
if x < p:
return ["below"]
Mar 15 '19 #1
Share this Question
Share on Google+
2 Replies


Expert 100+
P: 1,035
I'm not a python programmer meself but, I stored your code in a file name test.py:
Expand|Select|Wrap|Line Numbers
  1. python.exe c:\temp\test.py
  2.   File "c:\temp\test.py", line 4
  3.     y = []
  4.     ^
  5. IndentationError: expected an indented block
  6.  
H'm this is a thing you should/could have have detected before posting here.

If you do something like this:
Expand|Select|Wrap|Line Numbers
  1. a = [1,2,3]
  2. b = [4,5,6]
  3. c = [a,b]
  4. print(c)
  5.  
This returns: "[[1, 2, 3], [4, 5, 6]]"

So, the first line(s) of your code should look like:
Expand|Select|Wrap|Line Numbers
  1. above = []
  2. below = []
  3. y = [above, below]
  4.  
When printing y after this it returns: "[[], []]"
which seems to be more like you want it.
Mar 16 '19 #2

Expert 100+
P: 1,035
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 .. 😊
Mar 16 '19 #3

Post your reply

Sign in to post your reply or Sign up for a free account.