Hello everybody, I would like to know if there is a function which allows to know if a list contains a specified item. Thanks Fred
Hi! On Wed, 7 Jun 2000, QUIN FrИdИric wrote:
I would like to know if there is a function which allows to know if a list contains a specified item.
Learn Python! <!--#if "myitem in mylist"--> ... Oleg. (All opinions are mine and not of my employer) ---- Oleg Broytmann Foundation for Effective Policies phd@phd.russ.ru Programmers don't die, they just GOSUB without RETURN.
----- Original Message ----- From: QUIN Frédéric <frederic.quin@free.fr> To: <zope@zope.org> Sent: Wednesday, June 07, 2000 6:14 PM Subject: [Zope] How to know if a list contains a specified item ?
Hello everybody,
I would like to know if there is a function which allows to know if a list contains a specified item.
You can use: <dtml-if "list.count(item)"> If you want the (1st) index of the item in list you must use something like <dtml-let item1="1" item2="69"> <dtml-let list="[1,2,3]"> <dtml-try> <dtml-var "list.index(item1)"> <dtml-except>No item <dtml-var item1> </dtml-try> <dtml-try> <dtml-var "list.index(item2)"> <dtml-except>No item <dtml-var item2> </dtml-try> </dtml-let> </dtml-let> you have to use try because "list.index(item)" rise an exception if the "item" is not in list.. PM
On Wed, Jun 07, 2000 at 06:14:22PM +0200, QUIN Frédéric wrote:
I would like to know if there is a function which allows to know if a list contains a specified item.
Fred, You can use Python's "x in list" syntax as follows <dtml-let list="[1, 'a']"> <dtml-if "1 in list"> ... </dtml-if> . . <dtml-if "'a' in list"> ... </dtml-if> </dtml-let> ------------------------------------------------------ Andres Corrada-Emmanuel Email: andres@corrada.com ------------------------------------------------------
participants (4)
-
andres@corrada.com -
Marcel Preda -
Oleg Broytmann -
QUIN Fr�d�ric