19
加藤公一(はむかず)
Last seen 7 years ago
Member for 10 years, 3 months, 6 days
Difficulty Normal
1) Triangular number can be easily got as i*(i+1)//2 for i=1,2,...
sample code: [i*(i+1)//2 for i in range(n)]
2) Sorting in python is easy. Just use sorted()
3( You don't need temporary variable to swap the value. Use
a,b=b,a
for example.
More
It7s convenient to use the parameter "key" of the function "sorted." It specifies how it is sorted, not affecting the resulting list.
More
The module "itertools" has "combinations" and "permutations"
http://docs.python.org/2/library/itertools.html
More
the "replace" method of string class is convenient. Try "abc def gh".replace(" ","") for example.
More