Posted on 2007-12-04 07:04:47
I have been spinning in Python for a few days now in an attempt to port some C# bits. In the C# codebase, I typically exercised the following:
Listlist = new List (); list.Add(PreviouslyInstantiatedType); // Imagine many populators list.FindIndex(delegate(T) { T.someProperty == true; });
list = [] list.append(PreviouslyInstantiatedType) list.index(lambda x: x.someProperty == True)
def fIndex(f, list):
for i in xrange(len(list)):
if f(list[i]):
return i
return -1
class person:
def __init__(self, firstName, lastName):
self.firstName = firstName
self.lastName = lastName
people = [person('j','h'),person('k','a'),person('n','g')]
print fIndex(lambda p: p.lastName == 'a', people)
Art
ColdFusion
Data Visualizations
Design
Inspiration
JavaScript
Life
Python
Ruby
Snippets
Content by Kunal Anand. Connect with me on Twitter, Facebook, or email.