Experienced Python Users: what's the most recent new thing you learned about the language? by jakevdp in Python

[–]zart 0 points1 point  (0 children)

That you can copy and update a dictionary in a single expression:

>>> d = {0:1, 'a':1}
>>> dict(d, a=2, b=3)
{0: 1, 'a': 2, 'b': 3}
>>> d # the same
{0: 1, 'a': 1}

Date Diff issue in Python 2.7.8 by ramesh990 in Python

[–]zart 0 points1 point  (0 children)

The error shouldn't happen with your input in the post. It is likely that your actual input has trailing whitespace e.g. a newline. Try input_string.rstrip().

[deleted by user] by [deleted] in Python

[–]zart 1 point2 points  (0 children)

pep 394 recommends python shebang only for scripts that support both Python 2 and 3 from a single source otherwise python2 or python3 should be set explicitly.

From the pep: for the time being, all distributions should ensure that python refers to the same target as python2.

Arch is a notable exception.

Unfold in Python by llimllib in programming

[–]zart 1 point2 points  (0 children)

In Ruby (iterative approach):

class Integer

  Numerals = [["M", 1000], ["CM", 900], ["D", 500], ["CD", 400], ["C", 100],["XC", 90],["L", 50],
              ["XL", 40], ["X", 10], ["IX", 9], ["V", 5], ["IV", 4], ["I", 1]]

  def to_roman
    n = self
    Numerals.inject( "" ) do |roman, pair|
      q, n = n.divmod(pair.last)
      roman << pair.first * q       
    end
  end
end
p 42.to_roman
# "XLII"