By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,491 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,491 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"]
1 Week Ago #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 997
I'm not a python programmer meself but, I stored your code in a file name
Expand|Select|Wrap|Line Numbers
  1. python.exe c:\temp\
  2.   File "c:\temp\", line 4
  3.     y = []
  4.     ^
  5. 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:
Expand|Select|Wrap|Line Numbers
  1. a = [1,2,3]
  2. b = [4,5,6]
  3. c = [a,b]
  4. print(c)
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]
When printing y after this it returns: "[[], []]"
which seems to be more like you want it.
6 Days Ago #2

Expert 100+
P: 997
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 .. 😊
6 Days Ago #3

Post your reply

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