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
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:
>
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
> 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
>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
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,
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
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
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
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
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
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:
>
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
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
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:
15 matches
Mail list logo