<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman, new york, times, serif;font-size:12pt"><DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> 3Q very much!</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> What I really want to get is a c-style array, a pointer to the beginning of part of a list (or whatever alike). for example, I want to mutate part of a list, of course, I can achieve this by passing the pair list and (begin, end) as parameters. but in some case, this manner is quite tedious and in efficient (I think so, at least in C-style language it is so)!</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> I don't wanna get the '+' operator (which is powerful tool in scripting language), so I ignore this problem. thank you all the same!</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"> maybe this prolem looks silly, since I've just begun to study scripting language. <BR><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- Original Message ----<BR>From: Kent Johnson <kent37@tds.net><BR>Cc: tutor@python.org<BR>Sent: Monday, October 2, 2006 7:57:31 PM<BR>Subject: Re: [Tutor] how to make a reference to part of list?<BR><BR>
<DIV>Xie Chao wrote:<BR>> Namely, if list1 = {1, 2, 3}, and I wanna make a reference, say <BR>> "ref", to list1's sublist (which is also of type list), say {2, 3}, so <BR>> that when I make change to ref[0], then list1[1] will be changed!<BR>> But how can I make such a reference, 3x! <BR><BR>There is nothing built-in to Python that will let you do this. I don't <BR>think it would be too hard to write a class that does what you want for <BR>basic indexing operations. I would start with a copy of UserList (in <BR>module UserList). If you go beyond simple indexing and slicing I think <BR>you will have trouble. Say you have a class RefList that does what you <BR>want, and suppose you have<BR>a = [1, 2, 3]<BR>b = RefList(a, 1, 2)<BR>b is [2, 3]<BR>c = RefList(a, 0, 1)<BR>c is [1, 2]<BR><BR>Now what is the result of d=b+c? Is it a RefList with two references to
<BR>a, that looks like [1, 2, 2, 3]? What is the value of d after d[1] = 0? <BR>Is it [1, 0, 0, 3]?<BR><BR>Can you say more about why you want to do this? Maybe there is another <BR>solution.<BR><BR>By the way list literals in Python are written with square brackets [] <BR>not curly braces {}.<BR><BR>Kent<BR><BR><BR>_______________________________________________<BR>Tutor maillist - Tutor@python.org<BR><A href="http://mail.python.org/mailman/listinfo/tutor" target=_blank>http://mail.python.org/mailman/listinfo/tutor</A></DIV></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif"><BR></DIV></div><br></body></html>