beginner, idiomatic python

bambam david at asdf.asdf
Fri Aug 24 06:51:23 CEST 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']


"Scott David Daniels" <daniels at> wrote in message 
news:13cr00ujte4qs09 at
> bambam wrote:
>> Would someone like to suggest a replacement for this? It works ok,
>> but it doesn't look like any of the other code:
>> tempList = ['1','2','3','4','5','6','7','8']
>> sampleList=[]
>> for port in tempList:
>>     pagefound = False
>>     for i in range(self.parent.GetPageCount()):
>>         page=self.parent.GetPage(i)
>>         if hasattr(page, "port"):
>>             if page.port == int(port):
>>                 pagefound=True
>>         if not pagefound:
>>             sampleList.append(port)
>> Thanks!
> Look at good questions.  This is a _very_ underspecified question.
> One stab at mindreading:
>     def ported_pages(self):
>         for i in range(self.parent.GetPageCount()):
>             if hasattr(page, 'port'):
>                 yield page
>     ...
>         tempList = ['1','2','3','4','5','6','7','8']
>         missing = dict((int(v), v) for v in tempList)
>         for page in self.ported_pages():
>             if page.port in missing:
>                 missing.pop(page.port)
>                 if not missing:
>                     break
>         sampleList = missing.values()
>     ...
> -Scott David Daniels 

More information about the Python-list mailing list