-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontainer.py
56 lines (39 loc) · 1.15 KB
/
container.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# A Python program to show different
# ways to create Counter
from collections import Counter
from copy import copy
# With sequence of items copy Module
print(Counter(['B', 'B', 'A', 'B', 'C', 'A', 'B',
'B', 'A', 'C']))
print(copy(10))
# With pprint Module
import pprint
stuff = ['spam', 'eggs', 'lumberjack', 'knights', 'ni']
stuff.insert(0, stuff[:])
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(stuff)
pp = pprint.PrettyPrinter(width=41, compact=True)
pp.pprint(stuff)
tup = ('spam', ('eggs', ('lumberjack', ('knights', ('ni', ('dead',
('parrot', ('fresh fruit',))))))))
pp = pprint.PrettyPrinter(depth=6)
pp.pprint(tup)
# with enum module
from enum import Enum
class Season(Enum):
SPRING = 1
SUMMER = 2
AUTUMN = 3
WINTER = 4
# printing enum member as string
print(Season.SPRING)
# printing name of enum member using "name" keyword
print(Season.SPRING.name)
# printing value of enum member using "value" keyword
print(Season.SPRING.value)
# printing the type of enum member using type()
print(type(Season.SPRING))
# printing enum member as repr
print(repr(Season.SPRING))
# printing all enum member using "list" keyword
print(list(Season))