File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import struct
5+
6+ bmp_header = b'\x42 \x4d \x38 \x8c \x0a \x00 \x00 \x00 \x00 \x00 \x36 \x00 \x00 \x00 \x28 \x00 \x00 \x00 \x80 \x02 \x00 \x00 \x68 \x01 \x00 \x00 \x01 \x00 \x18 \x00 '
7+
8+ print (struct .unpack ('<ccIIIIIIHH' , bmp_header ))
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ from collections import namedtuple
5+
6+ Point = namedtuple ('Point' , ['x' , 'y' ])
7+ p = Point (1 , 2 )
8+ print ('Point:' , p .x , p .y )
9+
10+ from collections import deque
11+
12+ q = deque (['a' , 'b' , 'c' ])
13+ q .append ('x' )
14+ q .appendleft ('y' )
15+ print (q )
16+
17+ from collections import defaultdict
18+
19+ dd = defaultdict (lambda : 'N/A' )
20+ dd ['key1' ] = 'abc'
21+ print ('dd[\' key1\' ] =' , dd ['key1' ])
22+ print ('dd[\' key2\' ] =' , dd ['key2' ])
23+
24+ from collections import Counter
25+ c = Counter ()
26+ for ch in 'programming' :
27+ c [ch ] = c [ch ] + 1
28+ print (c )
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # -*- coding: utf-8 -*-
3+
4+ import hashlib
5+
6+ md5 = hashlib .md5 ()
7+ md5 .update ('how to use md5 in python hashlib?' .encode ('utf-8' ))
8+ print (md5 .hexdigest ())
9+
10+ sha1 = hashlib .sha1 ()
11+ sha1 .update ('how to use sha1 in ' .encode ('utf-8' ))
12+ sha1 .update ('python hashlib?' .encode ('utf-8' ))
13+ print (sha1 .hexdigest ())
You can’t perform that action at this time.
0 commit comments