954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

searching through a list with dicts

******************************
Sorry guys this works I tested with
bad values

******************************


Hello

I'm having trouble with this function i have a list with dicts and I'm trying to make a search in the list.
The problem is that my function doesn't return the list even though i know the values and types are correct

def dbsearch(db, element, val):
	for x in db:
		if x.get(element) == val:
			return x
		else:
			print "nope not in this one"


Any help or input is apreciated.

danfi766
Newbie Poster
2 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

So how did you solve it?

vegaseat
DaniWeb's Hypocrite
Moderator
5,989 posts since Oct 2004
Reputation Points: 1,345
Solved Threads: 1,417
 

Thats the embarrasing part. The code works fine. It was just my testing that was bad, I used a value that i thought would generate a true but afterwards i realized i should generate a false.

danfi766
Newbie Poster
2 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

so the problem is the "even though i know the values and types are correct" part in your initial statement :)

Gribouillis
Posting Maven
Moderator
2,786 posts since Jul 2008
Reputation Points: 1,044
Solved Threads: 691
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You