473,472 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

BANALE ma utile

Devo scoprire se un elemento esiste in una lista

Se metto confini.index(nomeelemento) mi da errore nel caso non esista e mi
da l'indice nel caso esista

Il mio problema è:
se l'elemento non esiste, devo fare la stessa cosa con un altro elemento.

Come posso evitare l'errore???
***
Avevo provato con

if confini.index(nomeelemento):
return qualcosa
else:
continue

***
Oppure con

if confini.index(nomeelemento)>-1:
return qualcosa
else:
continue

Ma nel caso non venga trovato l'elemento da errore
Jul 18 '05 #1
2 1352
Try this:

if nomeelemento in confini:
pass

k.

Armand Federico - INFO wrote:
Devo scoprire se un elemento esiste in una lista

Se metto confini.index(nomeelemento) mi da errore nel caso non esistae mi
da l'indice nel caso esista

Il mio problema è:
se l'elemento non esiste, devo fare la stessa cosa con un altro elemento.

Come posso evitare l'errore???


***
Avevo provato con

if confini.index(nomeelemento):
return qualcosa
else:
continue

***
Oppure con

if confini.index(nomeelemento)>-1:
return qualcosa
else:
continue

Ma nel caso non venga trovato l'elemento da errore



Jul 18 '05 #2
Armand Federico - INFO wrote:
Devo scoprire se un elemento esiste in una lista

Se metto confini.index(nomeelemento) mi da errore nel caso non esista e mi
da l'indice nel caso esista

Il mio problema è:
se l'elemento non esiste, devo fare la stessa cosa con un altro elemento.

Come posso evitare l'errore???
***
Avevo provato con

if confini.index(nomeelemento):
return qualcosa
else:
continue

***
Oppure con

if confini.index(nomeelemento)>-1:
return qualcosa
else:
continue

Ma nel caso non venga trovato l'elemento da errore


Prova a usare le eccezioni. Cioè fai

try:
return qualcosa
except IndexError:
continue

Marco
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

220
by: Brandon J. Van Every | last post by:
What's better about Ruby than Python? I'm sure there's something. What is it? This is not a troll. I'm language shopping and I want people's answers. I don't know beans about Ruby or have...
1
by: Saimon | last post by:
Questo Statement in SQL Server funziona. In Oracle PL/SQL se lo lancio funziona Quando lo devo far funzionare da Vb.net mi si pianta e non va avanti . Sta lì a pensare. Come mai ? UPDATE...
3
by: robert | last post by:
Hi everyone, I have a little question. In Visual studio 6 the MFC is based under API WIN 32. In dot net, the MFC of dot net, are based on API of dot net or on API WIN 32? And my last...
0
by: Logico | last post by:
Ciao a tutti, sto lavorando con ASP (non ASP.NET) e VBScript e avrei bisogno di definirmi delle mie Collection personalizzate, ma non riesco a trovare da nessuna parte la sintassi per crearle......
1
by: dark.magister | last post by:
sorry i don't speak very well english and this post is in italian in the link ther are a my firt program for clalcolate de resistor code sorry for my english
1
by: Sharon | last post by:
hi. i have a static method which has a locked code block. inside this lock i call other static utile methods in another class. the utile methods do not hold any state. i'm not sure what will...
2
by: Parret | last post by:
Ciao a tutto l'NG, proseguo col mio scontro con il C#.... Ieri mi sono trovato con l'esigenza di selezionare dalla rubrica di windows il nominativo e il numero di telefono di una persona, per poi...
42
by: Holger | last post by:
Hi guys Tried searching for a solution to this, but the error message is so generic, that I could not get any meaningfull results. Anyways - errormessage:...
3
by: NowSeeSharp | last post by:
Ciao a tutti, ho un problema probabilmente banale ma che non riesco a risolvere per caricare in modo statico una combobox di un valore chiave e un valore che venga visualizzato utilizzo il...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.