Re: About python while statement and pop()

2014-06-12 Thread hito koto
2014年6月12日木曜日 14時43分42秒 UTC+9 Steven D'Aprano:
 On Wed, 11 Jun 2014 21:56:06 -0700, hito koto wrote:
 
 
 
  I want to use while statement,
 
  
 
  for example:
 
  def foo(x):
 
  ... y = []
 
  ... while x !=[]:
 
  ... y.append(x.pop())
 
  ... return y
 
  ...
 
  print foo(a)
 
  [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 
  a
 
  []   but this is empty
 
  so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7,
 
  8, 9],[10]])
 
 
 
 
 
 I wouldn't use a while statement. The easy way is:
 
 
 
 py a = [[1, 2, 3, 4],[5, 6, 7, 8, 9],[10]]
 
 py y = a[::-1]
 
 py print y
 
 [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 
 py print a
 
 [[1, 2, 3, 4], [5, 6, 7, 8, 9], [10]]
 
 
 
 If you MUST use a while loop, then you need something like this:
 
 
 
 
 
 def foo(x):
 
 y = []
 
 index = 0
 
 while index  len(x):
 
 y.append(x[i])
 
 i += 1
 
 return y
 
 
 
 
 
 This does not copy in reverse order. To make it copy in reverse order, 
 
 index should start at len(x) - 1 and end at 0.
 
 
 
 
 
 
 
 -- 
 
 Steven

Hi, Steven:
Thanks,

My goal is to be able to in many ways python

Sorry, I was mistake,
I want to leave a number of previous (a = [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]] 
)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-12 Thread hito koto
2014年6月12日木曜日 14時43分42秒 UTC+9 Steven D'Aprano:
 On Wed, 11 Jun 2014 21:56:06 -0700, hito koto wrote:
 
 
 
  I want to use while statement,
 
  
 
  for example:
 
  def foo(x):
 
  ... y = []
 
  ... while x !=[]:
 
  ... y.append(x.pop())
 
  ... return y
 
  ...
 
  print foo(a)
 
  [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 
  a
 
  []   but this is empty
 
  so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7,
 
  8, 9],[10]])
 
 
 
 
 
 I wouldn't use a while statement. The easy way is:
 
 
 
 py a = [[1, 2, 3, 4],[5, 6, 7, 8, 9],[10]]
 
 py y = a[::-1]
 
 py print y
 
 [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 
 py print a
 
 [[1, 2, 3, 4], [5, 6, 7, 8, 9], [10]]
 
 
 
 If you MUST use a while loop, then you need something like this:
 
 
 
 
 
 def foo(x):
 
 y = []
 
 index = 0
 
 while index  len(x):
 
 y.append(x[i])
 
 i += 1
 
 return y
 
 
 
 
 
 This does not copy in reverse order. To make it copy in reverse order, 
 
 index should start at len(x) - 1 and end at 0.
 
 
 
 
 
 
 
 -- 
 
 Steven

Hi, Steven:
Thanks,

My goal is to be able to in many ways python

Sorry, I was mistake,
I want to leave a number of previous (a = [[10], [9, 8, 7, 6, 5], [4, 3, 2, 1]] 
)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-12 Thread hito koto
2014年6月12日木曜日 14時43分42秒 UTC+9 Steven D'Aprano:
 On Wed, 11 Jun 2014 21:56:06 -0700, hito koto wrote:
 
 
 
  I want to use while statement,
 
  
 
  for example:
 
  def foo(x):
 
  ... y = []
 
  ... while x !=[]:
 
  ... y.append(x.pop())
 
  ... return y
 
  ...
 
  print foo(a)
 
  [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 
  a
 
  []   but this is empty
 
  so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7,
 
  8, 9],[10]])
 
 
 
 
 
 I wouldn't use a while statement. The easy way is:
 
 
 
 py a = [[1, 2, 3, 4],[5, 6, 7, 8, 9],[10]]
 
 py y = a[::-1]
 
 py print y
 
 [[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 
 py print a
 
 [[1, 2, 3, 4], [5, 6, 7, 8, 9], [10]]
 
 
 
 If you MUST use a while loop, then you need something like this:
 
 
 
 
 
 def foo(x):
 
 y = []
 
 index = 0
 
 while index  len(x):
 
 y.append(x[i])
 
 i += 1
 
 return y
 
 
 
 
 
 This does not copy in reverse order. To make it copy in reverse order, 
 
 index should start at len(x) - 1 and end at 0.
 
 
 
 
 
 
 
 -- 
 
 Steven

Hi,
Thank you!
-- 
https://mail.python.org/mailman/listinfo/python-list


Python deepcopy to while statement

2014-06-12 Thread 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]



-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python deepcopy to while statement

2014-06-12 Thread 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])
 i -= 1
 return y
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python deepcopy to while statement

2014-06-12 Thread 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])
i -= 1
return y
-- 
https://mail.python.org/mailman/listinfo/python-list


About python while statement and pop()

2014-06-11 Thread hito koto
Hello,all
I'm first time,

I want to make a while statement which can function the same x.pop () and 
without the use of pop、how can i to do?

i want to change this is code:

def foo(x):
y = []
while x !=[]:
y.append(x.pop())
return y
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: About python while statement and pop()

2014-06-11 Thread hito koto
2014年6月12日木曜日 12時58分27秒 UTC+9 Chris Angelico:
 On Thu, Jun 12, 2014 at 1:40 PM, Vincent Vande Vyvre
 
 vincent.vandevy...@swing.be wrote:
 
  Le 12/06/2014 05:12, hito koto a écrit :
 
 
 
  Hello,all
 
  I'm first time,
 
 
 
  I want to make a while statement which can function the same x.pop () and
 
  without the use of pop、how can i to do?
 
 
 
  i want to change this is code:
 
 
 
  def foo(x):
 
   y = []
 
   while x !=[]:
 
   y.append(x.pop())
 
   return y
 
 
 
  Something like that :
 
 
 
  def foo(x):
 
  return reversed(x)
 
 
 
 That doesn't do the same thing, though. Given a list x, the original
 
 function will empty that list and return a new list in reverse order,
 
 but yours will return a reversed iterator over the original list
 
 without changing it. This is more accurate, but still not identical,
 
 and probably not what the OP's teacher is looking for:
 
 
 
 def foo(x):
 
 y = x[::-1]
 
 x[:] = []
 
 return y
 
 
 
 If the mutation of x is unimportant, it can simply be:
 
 
 
 def foo(x):
 
 return x[::-1]
 
 
 
 ChrisA


I want to use while statement,

for example:
 def foo(x):
... y = []
... while x !=[]:
... y.append(x.pop())
... return y
...
 print foo(a)
[[10], [5, 6, 7, 8, 9], [1, 2, 3, 4]]
 a
[]   but this is empty 
 so,I want to leave a number of previous (a = [[1, 2, 3, 4],[5, 6, 7, 8, 
 9],[10]])

-- 
https://mail.python.org/mailman/listinfo/python-list