beginner, idiomatic python

bambam david at asdf.asdf
Thu Aug 23 22:54:14 EDT 2007


Wos! Several different thoughts:

An object using yield to return only the relevant pages, one at a time.
Pop to remove the items from the list.
A dictionary to map between the strings and the integers.

The dictionary was particularly unexpected. Eventually, I
plan to change the string ports to device names. On the other
hand, it looks like the only reason I have port numbers is
to use as an index in things like this.

After examining your suggestion, I realised that another thing
I am interested in could be generalised: I want the complement
of the set of ports in pages, given a universal set in tempList.
Ignoring the break condition for the moment, and my problem
with int(port)/str(port), would you have offered a different solution
if I had asked for the relative complement of a small set?

a= ['a','b','c']
b= ['b']
c= a-b #set theoretic difference, a\b, a.~b, ['a','c']

Steve.

"Zentrader" <zentraders at gmail.com> wrote in message 
news:1187898049.734696.9500 at l22g2000prc.googlegroups.com...
> Does page count change? i.e. is it necessary to retrieve it in every
> loop or
> tempList = ['1','2','3','4','5','6','7','8']
> sampleList=[]
> page_count = self.parent.GetPageCount()
> <snipped>
>     for i in range(page_count):
>
> Also, once pagefound is set to True, all pages following will not be
> appended to sampleList because it is not initialized to False under
> the "for i in range(self.parent.GetPageCount())" loop.
>
> Finally, if I understand the logic and question correctly, you want
> something like
> tempList = ['1','2','3','4','5','6','7','8']
> sampleList=[]
> page_count = self.parent.GetPageCount()
> for port in tempList:
>    for i in range(page_count):
>        page=self.parent.GetPage(i)
>        if (hasattr(page, "port")) and (page.port != int(port)) :
>            sampleList.append(port)
>
> or perhaps (I'm not sure)
> tempList = [1, 2, 3, 4, 5, 6, 7, 8]
> sampleList=[]
> page_count = self.parent.GetPageCount()
> for i in range(page_count):
>        page=self.parent.GetPage(i)
>        if (hasattr(page, "port")) and (page.port not in tempList) :
>            sampleList.append(port)
> HTH
> 





More information about the Python-list mailing list