A community for students.
Here's the question you clicked on:
 0 viewing
anonymous
 5 years ago
Could someone help me with this Write a recursive function interleave, which takes a pair of two integer lists as input and returns a list which contains all the items of the input lists, but in alternating order
anonymous
 5 years ago
Could someone help me with this Write a recursive function interleave, which takes a pair of two integer lists as input and returns a list which contains all the items of the input lists, but in alternating order

This Question is Closed

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I'll be on again later tonight and I'll try to do it.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0What problems are you having with the function? What do you have so far?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I can'tget it to output the right thing

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0post the code and we can try to help, and should it be two lists or one list that is then broken int two ?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok it should output this >>>interleave ([1,2,3], [4,5,6,7]) [1,4,2,5,3,6,7]

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Why does it specifically have to be recursive?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0what should happen in the event of a >>>interleave ([1,2,3], [4,5,6,7,8,9,10])?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0That cant happen because I wrote the code for here last night that it splits them in half or if it is an odd number it makes the second list bigger by 1.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Here was my code lis=list(raw_input('Please enter a list:')) x=len(lis)/2 lis1=lis[:x] lis2=lis[x:] print lis1,lis2

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0if interleave([1,2,3],[4,5,6,7,8,9,10]) would output [1,4,2,5,3,6,7,8,9,10]

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0interleave is the opposite of the function u just wrote onyx, I tried zip with two list n I end up with a list of tuples

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0o ok I thought we were adding on to mine maybe as a simple shuffling method?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0well the split function that u wrote onyx is just say a subscript of a bigger method shuffle which calls interleave and split

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Yea so you would run split first and then interleave and you would do that repeatedly which would give you a shuffled deck. but since split is run first there would be no way to get a lisst with len 3 and one with length 7

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0thats good, leaves me to write less fail safes

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok this is shuffle:Define a function shuffle() which repeatedly splits a list in half, then interleaves the two resulting lists together. Your function should also take an additional integer parameter to control the number of split/interleave steps i.e.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok so do you want me to change mine to take an addition integer?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok so onyx are you interleaving or shuffling?, and what am i taking?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0shuffle output is:>>>shuffle (1, [1 ,2 ,3 ,4 ,5 ,6 ,7]) 1 ,4 ,2 ,5 ,3 ,6 ,7] >>>shuffle (2, [1 ,2 ,3 ,4 ,5 ,6 ,7]) (intermediate step  shuffle (1, [1 ,4 ,2 ,5 ,3 ,6 ,7]) ) [1 ,5 ,4 ,3 ,2 ,6 ,7]

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0also reckk, are we doing your work for you? because if you give us a better layout of the work we're doing for you, that'd be nice

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Reckk sorry but your thing didn't make any sense to me. Nessman I already did split but now it seems they want something new so I might have to do it over

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Onyx split is alright

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0no, it looks like he wants split, one function, interleave, another function, and shuffle a function that takes them both in order in an attempt to shuffle

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0also rekk, do you need a shuffle program, my dealing program is random, so you know

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Reck I'm not trying to be mean here but why try to make a go fish game if you can't code it yourself what practice is taking all our code copying and pasting it and seeing if output is right.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0no Onyx I compare ur codes with mine's

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0and try to make mine shorter

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0um then y don't you post the codes of what you have and we can make any necessary changes.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok def split(b): c=list(b) x=len(c)/2 a=c[:x] d=c[x:] return a,d

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok what about the shuffle one you need post what you have so far.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0that's where I am at now I tried interleave using zip but it didnt work

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0that's why I ask for u guys help

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0hey onyx, this if fun, and it doesn't hurt us. maybe this is part of a dumb pre req course he never plans to peruse. rekk i'll help you if you want to come clean that we are doing you work, i'll help you regardless, not sure about onyx, seems to have a problem with doing others work

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I will too I'm fine with helping I just want to know what were doing it for that's what I was trying to get to

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok it's basically an assignment , like the cesar cipher I sent u Nessman

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I am far from being a pro in python programming so I take or look for help wherever I can

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Ok that's fine is it for college,high school, or just a for fun assignment? And I'm working on it right now.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Nessman did you already do interleave()?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0no i have not, looking over his cipher functions, impressive method (thus far)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0it's for college the cesar cipher was the 1st assignment

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0this one is the 2nd,Nessman the deal() function that u wrote gave me a syntax error about the attribute of pop

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0try this code, its the final version, i uploaded the wrong one last night

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0oh I forgot here's a hint for interleave:[Hint: If a list is longer than the other then the additional elements should be placed at the end of the new list.]

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0i don't understand what your nested if loops in encode and decode do, and my style would have let me put the key as an argument so you need to know the magic number to unlock the data

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0and i don't like gen_decode and gen_encode, they don't tell you the key and don't let you input the key, you can't use one to reverse the other, its a little too random

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0well the lecturer asked for the opposite of all that u said, she let key=2 be a constant value in encode and decode so for a string encode('mad') would output 'ocf' and decode('ocf') would output 'mad'

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0gen_decode and gen_encode took gen_key which return a random key and the decode or encode the string but I messed up with the last part so it didn't work properly gen_decode should give u back what was gen_encode

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0well the problem is that you have no way of making sure they have the same key if its randomly generated, its a giant problem unless you can save the key with the output, then it becomes no more secure then encodedecode if you want to shave lines remove the key = 2/gencode lines, you only use the variable once, and it never changes, this only removes 5 lines total, but those can obviously be cut

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Hey reckk does it really have to be recursive because if not I think I'd be done by now. haha I never completely understood recursive functions so it takes me a while to write them.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0give me what you have onyx, i might be able to help recur it (recursive is not what i would choose in this situation)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0oh for the encode decode thing, if you can import specific words instead of the whole module, its just good style

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0def interleave(lis1,lis2): interWove=[lis1[0],lis2[0]] if len(lis1)>1 and len(lis2)>1: return interWove.append(interleave(lis1[1:],lis2[1:])) elif len(lis2)>1: return interWove.append(interleave(None,lis2[1:])) else: return interWove.append(interleave(lis1[1:],None)) print interleave([1,3,5,7],[2,4,6,8]) What I was trying to do was everytime it is called it will append just the first numbers(numbers in lis1[0],lis2[0]. but like I said I'm not good at recursive haha.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0This one works but only if they are the same length I have to go to bed so you can try and mod it to work with different lengths I know how, you can use if statements but I was trying to figure out a shorter way since you said you wanted short codes.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0def interleave(lis1,lis2): if len(lis1)==0 and len(lis2)==0: return [] interWove=[lis1[0],lis2[0]] print interWove return interWove+interleave(lis1[1:],lis2[1:]) print interleave([1,3,5,7],[2,4,6,8])

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok thanx onyx have a gud night

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Lol I always say I'm about to get off but i can't stop without finishing something haha here it is where it works for both. def interleave(lis1,lis2): if len(lis1)==0 and len(lis2)==0: return [] if len(lis1)==0: return lis2 if len(lis2)==0: return lis1 interWove=[lis1[0],lis2[0]] return interWove+interleave(lis1[1:],lis2[1:])

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0finished mine too. not as short, but it gets the job done

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0not sure what he means for both but mine will take uneven length lists without slowing down

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0okay so what is next on the docket?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0thats what I meant by both uneven and even and good night for real this time. haha

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Your code work perfectly I will try to mod it so it's concise but I like it Define a function shuffle() which repeatedly splits a list in half, then interleaves the two resulting lists together. Your function should also take an additional integer parameter to control the number of split/interleave steps i.e.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Shuffle outputs: >>>shuffle (1, [1 ,2 ,3 ,4 ,5 ,6 ,7]) 1 ,4 ,2 ,5 ,3 ,6 ,7] >>>shuffle (2, [1 ,2 ,3 ,4 ,5 ,6 ,7]) (intermediate step  shuffle (1, [1 ,4 ,2 ,5 ,3 ,6 ,7]) ) [1 ,5 ,4 ,3 ,2 ,6 ,7]

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0the file name says interleave but it has the entire interleave, split, and shuffle (split courtesy of onyx), it uses my version of interleave but will work with onyx's code, take her for a test drive, and once again my deal function is random, might cut out the entire shuffle stage on the final product

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok so wat was ur output for the deal function?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok my deal file wasn't the right one last night as well, or what ever i messed up earlier, this one produces a tuple with two parts, the first part is a list of hands, each hand being a list of tuples, each tuple being a card pair, and the second part of hte first tuple is the remaining cards in teh deck the hands are randomized

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0k interleave worked perfectly thanx agan

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0so if you enter "print deal(deck(),5,2)" you'll see what i mean, i just load my deck function strait into the dealing function, its a nice program, thank the man who made the random module

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0yeah they a very good a programming to come up wiith these module's

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0can I attach a pdf file here?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0only one way to find out

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0it doesn't work it took forever

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0n didn't work I have a cool python book that I wanted to share it has tons of python programs

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0perhaps you can post it online, do you have dropbox, or regularly use a file uploading service?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0no I don't only use em for uploading game file

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok try this link file:///C:/Documents%20and%20Settings/Maxin/My%20Documents/School%20work/Com%20sci/Python%20books/IYOCGwP_book1.pdf

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0that's a link to your local file, that's definitely not going to work for me, i need like a " http://dl.dropbox.com/u/18955243/How%20to%20use%20the%20Public%20folder.rtf " a link to a web adress, this link contains a text file introducing the public folder on the service called dropbox, dropbox is a good service, has a free option, i suggest you look into it

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok I am gonna look on it now, look at this final question for me please: Write a function askForcard() which takes a card and a hand and return a tuple where first part of the tuple is a Boolean value if the cardvalue is found in the hand. For example, if we are asking our opponent for a ‘J’ and the opponents hand is [('H', 'A'), ('D', 'J')] we are retuned tuple where first part is a boolean value indicating if the card is present and second part returns the position of the card in the opponents hand, if the card is not there just return 0 for position. E.g.

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0it outputs: >>> askForCard('J', [('H', 'A'), ('D', 'J')]) (True, 1) >>> askForCard('4', [('H', '2'), ('D', 'J')]) (False, 0) 7. when I finish implement everything I am gonna send it to u and u give me ur idea r ideas on how u could make the level of the computer more difficult

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok i'm tired, i'll work on it tomorrow? how far ahead of schedule are you?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0its due friday but go get some rest. hopefully u here 2marrow same time. I am gonna try the drop box thing b4 u leave so gimme 1015mins I just read it

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0thanks reckk, i'll read it when i'm not so tired

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0ok have a great night am gonna get some zzzzzzzzz's also

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0hola nessman did u check out the book

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0Hey what do you still need done?

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0a function askForcard() which takes a card and a hand and return a tuple where first part of the tuple is a Boolean value if the cardvalue is found in the hand. For example, if we are asking our opponent for a ‘J’ and the opponents hand is [('H', 'A'), ('D', 'J')] we are retuned tuple where first part is a boolean value indicating if the card is present and second part returns the position of the card in the opponents hand, if the card is not there just return 0 for position. E.g. >>> askForCard('J', [('H', 'A'), ('D', 'J')]) (True, 1) >>> askForCard('4', [('H', '2'), ('D', 'J')]) (False, 0)

anonymous
 5 years ago
Best ResponseYou've already chosen the best response.0I will try but Idk if I can do that one sorry

anonymous
 3 years ago
Best ResponseYou've already chosen the best response.0did u guys ever finish this assignment? because i need help with this same assignment and i can't access the files that was uploaded
Ask your own question
Sign UpFind more explanations on OpenStudy
Your question is ready. Sign up for free to start getting answers.
spraguer
(Moderator)
5
→ View Detailed Profile
is replying to Can someone tell me what button the professor is hitting...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 You have blocked this person.
 ✔ You're a fan Checking fan status...
Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.