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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
{
"metadata": {
"name": "",
"signature": "sha256:5233b8440acc7b2d62016ba76634e04bd09fd81a7f83bcd9847657fe204b0cea"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "heading",
"level": 1,
"metadata": {},
"source": [
"Chapter 23: Library Support for Numbers and Character Data"
]
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example tclassify.c, Page 613"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import string\n",
"print \" alnum alpha digit graph lower print punct space upper xdigit\"\n",
"p=\"azAZ0 !\\t\"\n",
"p1=list(p)\n",
"for i in p1:\n",
" listt=[\" \"]*10\n",
" print i,\n",
" if(i.isalnum()):\n",
" listt[0]=\" X\"\n",
" if(i.isalpha()):\n",
" listt[1]=\" X\"\n",
" if(i.isdigit()):\n",
" listt[2]=\" X\"\n",
" if(i.isspace()!=True):\n",
" listt[3]=\" X\"\n",
" if(i.islower()):\n",
" listt[4]=\" X\"\n",
" if(i in string.printable):\n",
" listt[5]=\" X\"\n",
" if(i in string.punctuation):\n",
" listt[6]=\" X\"\n",
" if(i.isspace()):\n",
" listt[7]=\" X\"\n",
" if(i.isupper()):\n",
" listt[8]=\" X\"\n",
" if(i in string.hexdigits):\n",
" listt[9]=\" X\"\n",
" print listt"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
" alnum alpha digit graph lower print punct space upper xdigit\n",
"a [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' X']\n",
"z [' X', ' X', ' ', ' X', ' X', ' X', ' ', ' ', ' ', ' ']\n",
"A [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' X']\n",
"Z [' X', ' X', ' ', ' X', ' ', ' X', ' ', ' ', ' X', ' ']\n",
"0 [' X', ' ', ' X', ' X', ' ', ' X', ' ', ' ', ' ', ' X']\n",
" [' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']\n",
"! [' ', ' ', ' ', ' X', ' ', ' X', ' X', ' ', ' ', ' ']\n",
"\t[' ', ' ', ' ', ' ', ' ', ' X', ' ', ' X', ' ', ' ']\n"
]
}
],
"prompt_number": 38
},
{
"cell_type": "heading",
"level": 2,
"metadata": {},
"source": [
"Example tcasemap.c, Page 615"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"p=\"aA0!\"\n",
"pl=list(p)\n",
"for i in pl:\n",
" print \"tolower('%c') is '%c'; \"% (i,i.lower()),\n",
" print \"toupper('%c') is '%c'; \"% (i,i.upper())"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"tolower('a') is 'a'; toupper('a') is 'A'; \n",
"tolower('A') is 'a'; toupper('A') is 'A'; \n",
"tolower('0') is '0'; toupper('0') is '0'; \n",
"tolower('!') is '!'; toupper('!') is '!'; \n"
]
}
],
"prompt_number": 1
},
{
"cell_type": "code",
"collapsed": false,
"input": [],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
}
]
}
|