CodEx - Important Notes

From MT Talks
Jump to: navigation, search

This page is dedicated to the technical issues regarding CodEx.

You are doing an exercise. You have a solution. It runs perfectly on your computer. You are happy. You submit your solution to CodEx.

Oops, your solution failed with weird and unuseful log. This page is designed to help you!



Python

It seems that CodEx is running Python 2.5 or 2.6. The following features are not available.

Unavailable features

Dict comprehension

   >>> {x: x**2 for x in (2, 4, 6)}
   {2: 4, 4: 16, 6: 36}

Solution: Use the dict constructor:

   >>> dict((x, x**2) for x in (2, 4, 6))
   {2: 4, 4: 16, 6: 36}

collections.Counter

   >>> from collections import Counter
   >>> c = Counter()
   >>> c.update(['the', 'cat', 'sat', 'on', 'the', 'mat'])
   >>> c['the']
   2

Solution: Use defaultdict:

   >>> from collections import defaultdict
   >>> c = defaultdict(int)
   >>> for w in ['the', 'cat', 'sat', 'on', 'the', 'mat']:
   ...     c[w] += 1
   ... 
   >>> c['the']
   2

Other problems

Trying to read from sys.stdin causes an error. Use fileinput:

   import fileinput
   
   for line in fileinput.input():
      print line

Java

C++

C

Pascal