How to split a string of space separated numbers into integers?

Use str.split(): >>> “42 0″.split() # or .split(” “) [’42’, ‘0’] Note that str.split(” “) is identical in this case, but would behave differently if there were more than one space in a row. As well, .split() splits on all whitespace, not just spaces. Using map usually looks cleaner than using list comprehensions when you … Read more

Using int vs Integer

the Integer class is provided so that values can be boxed/unboxed in a pure OO manner. use int where appropriate unless you specifically need to use it in an OO way; in which case Integer is appropriate. Java Int vs Integer However, very different things are going on under the covers here. An int is … Read more

Converting characters to integers in Java

Character.getNumericValue(c) The java.lang.Character.getNumericValue(char ch) returns the int value that the specified Unicode character represents. For example, the character ‘\u216C’ (the roman numeral fifty) will return an int with a value of 50. The letters A-Z in their uppercase (‘\u0041’ through ‘\u005A’), lowercase (‘\u0061’ through ‘\u007A’), and full width variant (‘\uFF21’ through ‘\uFF3A’ and ‘\uFF41’ through … Read more

Numpy integer nan [duplicate]

No, you can’t, at least with current version of NumPy. A nan is a special value for float arrays only. There are talks about introducing a special bit that would allow non-float arrays to store what in practice would correspond to a nan, but so far (2012/10), it’s only talks. In the meantime, you may … Read more