<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">&nbsp;&nbsp; 3Q very much!</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;&nbsp; What I really want to get is a c-style array, a pointer to the beginning of part of a list (or whatever alike).&nbsp;for example, I want to mutate part of a list, of course, I can achieve this by passing the pair list and&nbsp;(begin, end) as parameters. but in some case,&nbsp;this manner is&nbsp;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">&nbsp;&nbsp;&nbsp; I don't wanna get the '+' operator (which is powerful tool in scripting language), so I ignore&nbsp;this problem. thank you all the same!</DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">&nbsp;&nbsp;&nbsp; maybe this prolem looks silly,&nbsp;since I've just begun to study&nbsp;scripting language.&nbsp;<BR><BR></DIV>
<DIV style="FONT-SIZE: 12pt; FONT-FAMILY: times new roman, new york, times, serif">----- Original Message ----<BR>From: Kent Johnson &lt;kent37@tds.net&gt;<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>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Namely, if&nbsp;&nbsp;list1 = {1, 2, 3}, and I wanna make a reference, say <BR>&gt; "ref",&nbsp;&nbsp;to list1's sublist (which is also of type list), say {2, 3}, so <BR>&gt; that when I make change to ref[0], then list1[1] will be changed!<BR>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; But how can I make such a reference, 3x!&nbsp;&nbsp;<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&nbsp;&nbsp;-&nbsp;&nbsp;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>