inicio mail me! sindicaci;ón

Generics are cool, but Python is cooler

My friend Valentino has posted on his blog about a sample of code with C# and generics and he rewrote the sample in Python ;)

Here the samples:

C# 2.0:
List integers = new List();
for(int i=1; i< =10; i++) integers.Add(i);
int sum;
integers.ForEach(delegate(int i){ sum+=i; });

vs

Python (basically any version):
sum([x for x in xrange(11)])

Related posts

  • Installing stuff in Parallels
  • Generics in CLR (part two)
  • Quote of the month
  • Paid Tha Cost to Be Da Boss
  • Generics Aren’t
  • Gravatar

    Anonymous said,

    August 24, 2004 @ 12:29 am

    I hate to say it, but this works only in Python 2.3 or higher. In Python 2.2 and below you get “NameError: name ’sum’ is not defined”. Still, Python’s cooler. :)

    RSS feed for comments on this post · TrackBack URI

    Leave a Comment