473,491 Members | 2,248 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Which is the best way of checking the empty list or dict?

440 Contributor
Hi,

Whether we can check the empty list or dict by i"f "conditon or catch this exception by "try" and "catch" blocks.

Which will be the best practctice?.

In my work I have to play with more list and dictionaries variables.SO every where I have to check whether the dict or list is empty.

Thanks
PSB
Apr 12 '07 #1
1 13809
ghostdog74
511 Recognized Expert Contributor
to check empty list , dictionary , use not

Expand|Select|Wrap|Line Numbers
  1. >>> dict1 = {}
  2. >>> not dict1
  3. True
  4. >>> list1 = []
  5. >>> not list1
  6. True
  7.  
please readthe docs on "More on conditions".
Apr 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

26
15514
by: Alex Panayotopoulos | last post by:
Hello all, Maybe I'm being foolish, but I just don't understand why the following code behaves as it does: - = - = - = - class listHolder: def __init__( self, myList= ): self.myList =...
3
1630
by: Dave Opstad | last post by:
I fully understand why this happens: ---------------------------- >>> a = , , , , ] >>> b = ] * 5 >>> a , , , , ] >>> b , , , , ] >>> a == b
59
8727
by: Steve R. Hastings | last post by:
So, Python 2.5 will have new any() and all() functions. http://www.python.org/dev/peps/pep-0356/ any(seq) returns True if any value in seq evaluates true, False otherwise. all(seq) returns...
8
2674
by: per9000 | last post by:
Hi, I wanted to test to compile an application I build for .NET 2.0 in with the 1.1 C# compiler. I encountered difficulties since I had a List<myClass>. I found a list of what is new in .NET 2.0...
7
18635
by: Rehceb Rotkiv | last post by:
I want to check whether, for example, the element myList exists. So far I did it like this: index = -3 if len(myList) >= abs(index): print myList Another idea I had was to (ab-?)use the...
6
2973
by: psbasha | last post by:
Hi, I am assigning the list/dict values to another list/dict variable as shown below. List : List1 = List2 = List1
1
1396
by: Tzury Bar Yochay | last post by:
while I can invoke methods of empty string '' right in typing (''.join(), etc.) I can't do the same with empty list example: I would not use b = a since I don't want changes on 'b' to...
0
965
by: Alexnb | last post by:
Okay this is a simple question I just don't know how. If I have a list, say: funList = and after a while something possible should have been appended to it, but wasn't. How can I test if that...
2
1927
by: Matthew Fitzgibbons | last post by:
Alexnb wrote: if not funList: do_something() -Matt
0
6978
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7190
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
6858
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
7360
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4578
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3086
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
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
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 ...
1
633
muto222
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.