- 博客(6)
- 收藏
- 关注
转载 Are there dictionary comprehensions in Python? (Problem with function returning dict)
I know about list comprehensions, what about dictionary comprehensions?Expected Output:>>> countChar('google') {'e': 1, 'g': 2, 'l': 1, 'o': 2} >>> countLetters('apple') {'a': 1, 'e'
2014-01-20 10:14:13 778
转载 python one-line list comprehension: if-else variants
It's more about python list comprehension syntax. I've got a list comprehension that produces list of odd numbers of a given range:[x for x in range(1, 10) if x % 2]This makes a filter - I've go
2014-01-20 10:09:06 3046
原创 在同一个位置更新进度
#include#include#includeint main(){ char *backSpaces = "\b\b"; printf( "00" ); for ( int process = 0 ; process < 100 ; process++) { printf("%s%02d",backSpaces,process);
2014-01-18 13:52:04 716
转载 Difference between __str__ and __repr__ in Python
Unless you specifically act to ensure otherwise, most classes don't have helpful results for either:>>> class Sic(object): pass... >>> print str(Sic())__main__.Sic object at 0x8b7d0>>>> print re
2014-01-03 16:16:18 1387
原创 Raise and Handle Exception Demo
import sysclass MyError(Exception): def __init__(self,value): self.value = value def __str__(self): return repr(self.value)try: f = open('new.in') s = f.readline() f.close() i = int(s.st
2014-01-02 16:07:38 547
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人