Python deepcopy to while statement

Discussion in 'Python' started by hito koto, Jun 13, 2014.

  1. hito koto

    hito koto Guest

    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]
     
    hito koto, Jun 13, 2014
    #1
    1. Advertisements

  2. hito koto

    hito koto Guest

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

    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
     
    hito koto, Jun 13, 2014
    #2
    1. Advertisements

  3. hito koto

    hito koto Guest

    2014年6月13日金曜日 12時47分19秒 UTC+9 hito koto:
    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
     
    hito koto, Jun 13, 2014
    #3
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.