Re: How to improve this code?

2009-09-18 Thread Sergey Simonenko
elements_present = lambda seq, match: any(((x in match) for x in seq)) On Mon, 14 Sep 2009 19:08:59 -0600, Oltmans wrote: Hello, Is there someway I can improve the following code(pythonically)? (Copying from IDLE) match=[1,2,3,4,5] def elementsPresent(aList): result=False if

Re: How to improve this code?

2009-09-18 Thread Simon Forman
On Sep 14, 9:08 pm, Oltmans wrote: > Hello, > > Is there someway I can improve the following code(pythonically)? > (Copying from IDLE) > match=[1,2,3,4,5] > > def elementsPresent(aList): >         result=False >         if not aList: >                 return False >         for e in aList: >      

Re: Fwd: Re: How to improve this code?

2009-09-16 Thread Duncan Booth
Hendrik van Rooyen wrote: > def are_elements_present(eleLocators): > elePresent=False > if not eleLocators: > return False > > for ele in eleLocators: > if selenium.is_element_present(ele): > elePresent=True > else: > elePresent=False

Re: Fwd: Re: How to improve this code?

2009-09-16 Thread Thomas Lehmann
> otherwise. Given this, I'm just trying to write a method > are_elements_present(aList) whose job is to return True if and only if > all elements in aList are present in page's HTML. So here is how > missingItems = [str(ele) for ele in eleLocators if not selenium.is_element_present(ele)] if len(m

Fwd: Re: How to improve this code?

2009-09-16 Thread Hendrik van Rooyen
>From a private email, forwarded to the list: -- Forwarded Message -- Subject: Re: How to improve this code? Date: Tuesday 15 September 2009 From: Oltmans To: hend...@microcorp.co.za On Sep 15, 1:13 pm, Hendrik van Rooyen wrote: > > (i) a True if All the elements

Re: How to improve this code?

2009-09-15 Thread Andreas Waldenburger
On Mon, 14 Sep 2009 18:33:17 -0700 (PDT) André wrote: > Here's an example using sets: > > >>> def is_present(list_1, list_2): > ...if set(list_1).intersection(set(list_2)): > ... return True > ...return False > ... Not that it matters, but I'd probably write: def is_present(test,

Re: Re: How to improve this code?

2009-09-15 Thread Dave Angel
Oltmans wrote: On Sep 15, 1:13 pm, Hendrik van Rooyen wrote: (i) a True if All the elements in match are in aList, else False? (ii) a True if any one or more of the members of match are in aList? (iii) Something else? That's a good question because I failed miserably in explainin

Re: How to improve this code?

2009-09-15 Thread Tim Golden
Tim Golden wrote: Unless I'm missing something, (and I didn't bother to read the original code so I may be) that's a subset test: set (searchList) <= set (searchList) (cough) or, rather: set (searchList) <= set (sourceList) TJG -- http://mail.python.org/mailman/listinfo/python-list

Re: How to improve this code?

2009-09-15 Thread Tim Golden
Sol Toure wrote: def are_elements_present(sourceList, searchList):for e in searchList: if e not in sourceList: return False return True Using set: def are_elements_present(sourceList, searchList): return len(set(sourceList).intersection(set(searchList

Re: How to improve this code?

2009-09-15 Thread Sol Toure
def are_elements_present(sourceList, searchList):for e in searchList: if e not in sourceList: return False return True Using set: def are_elements_present(sourceList, searchList): return len(set(sourceList).intersection(set(searchList)) == len(searchLis

Re: How to improve this code?

2009-09-15 Thread Oltmans
On Sep 15, 1:13 pm, Hendrik van Rooyen wrote: > > (i) a True if All the elements in match are in aList, else False? > (ii) a True if any one or more of the members of match are in aList? > (iii) Something else? That's a good question because I failed miserably in explaining my problem clearl

Re: How to improve this code?

2009-09-15 Thread Hendrik van Rooyen
On Tuesday 15 September 2009 03:08:59 Oltmans wrote: > match=[1,2,3,4,5] > > def elementsPresent(aList): > result=False > if not aList: > return False > for e in aList: > if e in match: > result=True > else: >

Re: How to improve this code?

2009-09-14 Thread Tim Chase
def elementsPresent(aList, match): match = set(match) for item in aList: if item in match: return True return False This could be rewritten in Python2.5+ as def elementsPresent(aList, match): match = set(match) return any(elem in match for elem in

Re: How to improve this code?

2009-09-14 Thread André
On Sep 14, 10:16 pm, "Diez B. Roggisch" wrote: > Oltmans schrieb: > > > > > Hello, > > > Is there someway I can improve the following code(pythonically)? > > (Copying from IDLE) > > match=[1,2,3,4,5] > > > def elementsPresent(aList): > >    result=False > >    if not aList: > >            return F

Re: How to improve this code?

2009-09-14 Thread Diez B. Roggisch
Oltmans schrieb: Hello, Is there someway I can improve the following code(pythonically)? (Copying from IDLE) match=[1,2,3,4,5] def elementsPresent(aList): result=False if not aList: return False for e in aList: if e in match: