Python deepcopy to while statement

H

hito koto

Hi, all

I want to make the function use while statement,and without a deepcopy functions.

this is my use deepcopy function correct codes, So, how can i to do a different way and use while statement:

def foo(x):
if not isinstance(x, list):
return x
return [foo(y) for y in x]
 
H

hito koto

2014年6月13日金曜日 12時47分19秒 UTC+9 hito koto:
Hi, all



I want to make the function use while statement,and without a deepcopy functions.



this is my use deepcopy function correct codes, So, how can i to do a different way and use while statement:



def foo(x):

if not isinstance(x, list):

return x

return [foo(y) for y in x]


I write this code but this is not copy:
maybe noe more write while statements: but i can't.

def foo(x):
y = []
i = len(x)-1
while i >= 0:
y.append(x)
i -= 1
return y
 
H

hito koto

2014年6月13日金曜日 12時47分19秒 UTC+9 hito koto:
Hi, all



I want to make the function use while statement,and without a deepcopy functions.



this is my use deepcopy function correct codes, So, how can i to do a different way and use while statement:



def foo(x):

if not isinstance(x, list):

return x

return [foo(y) for y in x]

I write this code but this is not copy:
maybe have to write one more the while statements: but i can't.


def foo(x):
y = []>
i = len(x)-1
while i >= 0:
y.append(x)
i -= 1
return y
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top