anonymous
  • anonymous
can anyone help with this? Write a program in python that splits a list of integers in a tuple of two list the first list is half the given integer value of the given integer list and the second is the second half of the integer list (if the list length is odd then the second half of the pair should be longer) eg . ([1,3,5,6,11,5,6]) => ([1,3,5], [6,11,5,6]0
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
chestercat
  • chestercat
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
rsmith6559
  • rsmith6559
myTuple = ([1,3,5,6,11,5,6],) myTuple += ([],) index = len(myTuple[0] ) // 2 while( len( myTuple[0] ) > index ): myTuple[1].append( myTuple[0].pop( index ) ) print myTuple
anonymous
  • anonymous
Should be as simple as. split = len(myTuple[])/2 firstlist = myTuple[0:split] secondlist myTuple[split + 1:]
carlsmith
  • carlsmith
lando pretty much nailed it there, but I just wondered why there is an empty list on line one? split = len(myTuple[])/2 That'll throw a syntax error. It should read split = len(myTuple)/2 I would've thought.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

rsmith6559
  • rsmith6559
I'll admit that I may have overdone the loop, but neither of these two snippets will produce the output in the example from the input.
carlsmith
  • carlsmith
This seems to do the job.
rsmith6559
  • rsmith6559
Yes it does.
anonymous
  • anonymous
Hmmm, I don't code in Python so the syntax is a bit off. It seems to me that the logic is correct and it runs in constant time vs O(n) time for your solution rsmith.
anonymous
  • anonymous
Carls implementation is a nicer than mine of course.
carlsmith
  • carlsmith
I just try to keep it Pythonic. Simple is beautiful, never optimise prematurely. I did like your solution ~ it just does the job, no nonsense ~ you just got the Python a bit off.
anonymous
  • anonymous
I've got to get used to the fact that Python can return multiple values from a method. I'm used to only being able to return one value.

Looking for something else?

Not the answer you are looking for? Search for more explanations.