-5

I have a program that finds the index of the largest value of an array and then from that point it splits it into two subarrays. Here's what it looks like:

def main():
   numbers = eval(input("Give me an array of numbers: "))
   largest = numbers[0]
   ind = numbers.index(max(numbers))
   print("Index of the largest number: ", ind)
   ar1, ar2 = numbers[0:ind], numbers[ind:]
   print("First subarray: ", ar1)
   print("Second subarray: ", ar2)
main()

Now I want it count the number of times the first value in the first subarray appears in the second subarray. How can I do that?

user3518112
  • 21
  • 1
  • 5
  • 3
    So you'll complete your entire project asking questions? – devnull Apr 11 '14 at 18:35
  • Why not post the entire assignment in one go. – devnull Apr 11 '14 at 18:35
  • I saw three answers pop up in 30 seconds – Jerry Meng Apr 11 '14 at 18:35
  • Possible _extension_ of http://stackoverflow.com/questions/23019773/locate-the-index-of-largest-value-in-an-array-python – devnull Apr 11 '14 at 18:37
  • Do you want the largest number to be at the end of the first list or the beginning of the second list or just be removed? – s16h Apr 11 '14 at 18:38
  • You use the code from the answers that you [receive](http://stackoverflow.com/questions/23019773/locate-the-index-of-largest-value-in-an-array-python) but still don't accept those? – devnull Apr 11 '14 at 18:38
  • What kind of input are you expecting a user to give you for `eval(input('Give me an array of numbers: '))`? Because right now it would take a user typing _a valid Python list_ (not very user friendly) and of course is exposed to all the badness of `eval` (like the "array of number" `import os;os.system('rm -rf /')`) – Two-Bit Alchemist Apr 11 '14 at 18:38

2 Answers2

1

Array slicing?

ar1, ar2 = numbers[0:ind], numbers[ind:]
print ar1
print ar2
ajm475du
  • 361
  • 1
  • 5
0

You can use slice:

print numbers[:ind], numbers[ind:]

numbers[:ind] prints elements from 0 to ind-1. numbers[ind:] prints elements from ind to last element

venpa
  • 4,268
  • 21
  • 23