I have list of integers, from which I would first like to get unique numbers, first ordered by their occurrences and then the numbers with equal counts should be ordered in descending order.
example 1:
input1 = [1,2,2,1,6,2,1,7]
expected output = [2,1,7,6]
explanation: both 2 and 1 appear thrice while 6 and 7 appear once. so, the numbers occurring thrice will be placed first and in descending order; and same for the set that appears once.
another example case:
input_2 = list(map(int, '40 29 2 44 30 79 46 85 118 66 113 52 55 63 48 99 123 51 110 66 40 115 107 46 6 114 36 99 13 108 85 39 14 121 42 37 56 11 104 28 24 123 63 51 118 52 120 28 64 43 44 86 42 71 101 78 93 1 6 14 42 33 88 107 35 70 74 30 54 76 27 91 115 71 63 103 94 109 39 4 16 108 97 83 29 57 86 121 53 94 28 7 5 31 123 21 2 17 112 104 75 124 88 30 108 14 65 118 28 81 80 14 14 107 21 60 47 97 50 53 19 112 43 46'.split()))
output_2 = list(map(int, '14 28 123 118 108 107 63 46 42 30 121 115 112 104 99 97 94 88 86 85 71 66 53 52 51 44 43 40 39 29 21 6 2 124 120 114 113 110 109 103 101 93 91 83 81 80 79 78 76 75 74 70 65 64 60 57 56 55 54 50 48 47 37 36 35 33 31 27 24 19 17 16 13 11 7 5 4 1'.split()))
This was from a coding test I took. This must be solved without using functions from imports like collections, itertools etc,. and using functions already available in python's namespace like dict, sorted is allowed. How do I do this as efficiently as possible?
def sort_sort(input1):
a = {i:input1.count(i) for i in set(input1)}
b ={i:[] for i in set(a.values())}
for k,v in a.items():
b[v].append(k)
for v in b.values():
v.sort(reverse=True)
output=[]
quays =list(b.keys())
quays.sort(reverse=True)
for q in quays:
output +=b[q]
print(output)
I wish to plot XRD patterns in a multiplot environment. The XRD patterns are plotted separately and they seem to be fine but the stacked plot shows random texts, symbols at various multiplots. Data file is given below.
# XRD
15 117 182 176 189
15.05 129 207 186 166
15.1 129 213 158 144
15.15 137 156 159 167
15.2 148 191 179 150
15.25 116 202 176 142
15.3 162 206 153 139
15.35 125 184 129 147
15.4 130 180 146 150
15.45 145 212 134 137
15.5 119 193 166 127
15.55 118 195 152 161
15.6 148 201 150 131
15.65 122 188 152 154
15.7 121 172 142 155
15.75 125 163 129 141
15.8 121 180 123 151
15.85 124 170 134 135
15.9 118 197 126 147
15.95 135 185 153 142
16 127 161 154 162
16.05 126 196 155 151
16.1 105 184 146 157
16.15 123 191 133 128
16.2 115 185 128 130
16.25 143 184 140 126
16.3 112 164 178 135
16.35 119 174 123 136
16.4 113 168 130 133
16.45 111 188 123 143
16.5 120 179 109 165
16.55 113 156 131 128
16.6 105 175 153 136
16.65 119 170 114 143
16.7 117 155 151 143
16.75 112 144 141 130
16.8 116 153 142 148
16.85 128 166 121 137
16.9 119 136 124 152
16.95 91 160 111 124
17 95 153 123 125
17.05 119 140 133 133
17.1 112 140 134 127
17.15 114 152 118 129
17.2 123 164 113 139
17.25 106 155 134 120
17.3 114 153 121 120
17.35 100 151 118 142
17.4 105 152 119 152
17.45 86 127 117 133
17.5 105 156 118 129
17.55 90 150 117 143
17.6 94 137 116 117
17.65 104 150 95 118
17.7 102 140 89 129
17.75 99 146 114 128
17.8 123 142 115 126
17.85 93 146 149 128
17.9 90 147 125 135
17.95 86 121 102 136
18 91 123 110 124
18.05 99 117 103 140
18.1 106 125 88 138
18.15 93 124 91 118
18.2 94 138 100 133
18.25 108 108 115 110
18.3 97 122 111 118
18.35 92 132 90 124
18.4 88 130 101 129
18.45 94 120 112 118
18.5 108 124 94 150
18.55 100 118 105 110
18.6 87 136 134 112
18.65 121 107 85 130
18.7 94 131 101 124
18.75 86 134 104 117
18.8 108 138 107 122
18.85 101 133 112 113
18.9 83 112 88 126
18.95 94 107 123 123
19 83 137 110 123
19.05 85 136 102 137
19.1 107 110 82 122
19.15 82 121 92 118
19.2 84 128 114 141
19.25 94 109 103 108
19.3 81 119 102 105
19.35 96 119 95 112
19.4 84 82 86 120
19.45 88 105 97 106
19.5 119 114 91 134
19.55 77 91 102 125
19.6 84 124 108 133
19.65 73 117 92 121
19.7 86 119 104 134
19.75 75 125 84 135
19.8 108 122 80 121
19.85 89 91 91 104
19.9 80 90 105 132
19.95 85 108 78 131
20 88 114 93 129
20.05 92 97 78 142
20.1 96 111 105 120
20.15 88 114 94 115
20.2 84 100 86 121
20.25 100 100 80 132
20.3 94 84 88 147
20.35 84 101 78 111
20.4 78 105 89 112
20.45 81 86 98 129
20.5 86 111 89 127
20.55 92 92 83 120
20.6 85 90 86 121
20.65 74 90 89 141
20.7 83 103 71 141
20.75 74 98 99 114
20.8 87 75 83 149
20.85 67 96 82 154
20.9 85 93 80 174
20.95 83 109 95 157
21 90 97 83 211
21.05 81 105 66 277
21.1 87 94 86 446
21.15 84 97 92 443
21.2 83 101 90 446
21.25 84 100 88 421
21.3 86 107 90 357
21.35 92 97 101 297
21.4 92 112 89 352
21.45 73 108 91 321
21.5 97 130 94 346
21.55 96 128 90 480
21.6 88 121 88 663
21.65 95 107 74 941
21.7 93 95 75 1106
21.75 83 83 67 1078
21.8 91 101 70 966
21.85 91 108 78 815
21.9 76 95 87 792
21.95 85 74 94 629
22 89 86 70 593
22.05 87 81 88 402
22.1 72 73 81 289
22.15 85 90 69 240
22.2 71 94 76 188
22.25 68 74 70 160
22.3 75 96 72 146
22.35 63 82 64 156
22.4 64 77 61 145
22.45 76 84 73 140
22.5 72 98 64 128
22.55 78 73 91 126
22.6 62 95 64 113
22.65 80 74 80 119
22.7 80 85 72 132
22.75 78 80 79 98
22.8 85 72 78 140
22.85 62 88 69 115
22.9 74 94 71 126
22.95 84 91 78 131
23 73 69 79 106
23.05 76 78 66 133
23.1 83 84 79 115
23.15 48 84 77 97
23.2 74 91 62 111
23.25 79 99 58 116
23.3 75 77 53 126
23.35 70 94 67 163
23.4 94 84 70 161
23.45 80 74 69 175
23.5 79 74 65 213
23.55 69 75 67 206
23.6 73 91 72 225
23.65 55 78 81 191
23.7 72 99 68 180
23.75 59 87 81 191
23.8 87 100 69 183
23.85 76 95 76 172
23.9 70 97 74 207
23.95 76 90 75 281
24 74 87 69 359
24.05 76 81 67 443
24.1 89 74 68 472
24.15 79 72 53 429
24.2 84 73 72 345
24.25 72 82 59 313
24.3 69 71 71 300
24.35 74 92 85 283
24.4 72 94 65 245
24.45 85 89 69 186
24.5 65 90 80 156
24.55 85 100 69 102
24.6 68 77 69 116
24.65 71 74 76 121
24.7 70 77 61 119
24.75 70 75 70 118
24.8 75 65 70 115
24.85 73 73 80 124
24.9 79 93 62 98
24.95 76 76 78 104
25 78 75 55 95
25.05 68 77 66 107
25.1 67 82 71 83
25.15 62 73 74 106
25.2 72 88 56 113
25.25 65 86 65 108
25.3 78 70 71 103
25.35 74 73 63 93
25.4 67 62 90 110
25.45 77 98 74 88
25.5 70 78 60 101
25.55 82 81 54 107
25.6 80 62 65 97
25.65 64 91 64 95
25.7 71 74 71 91
25.75 67 75 58 81
25.8 70 78 74 76
25.85 73 95 62 94
25.9 80 78 67 96
25.95 69 86 66 88
26 61 71 71 102
26.05 82 72 63 95
26.1 86 75 57 106
26.15 83 80 62 84
26.2 88 74 65 85
26.25 68 76 60 104
26.3 78 70 58 92
26.35 66 74 70 107
26.4 71 68 60 93
26.45 69 81 77 105
26.5 61 74 79 81
26.55 73 81 60 82
26.6 74 79 56 84
26.65 83 97 81 97
26.7 72 78 64 92
26.75 82 79 66 104
26.8 84 77 49 85
26.85 72 79 58 95
26.9 68 77 70 89
26.95 72 82 62 82
27 63 75 68 83
27.05 66 74 66 82
27.1 68 78 48 102
27.15 65 85 52 93
27.2 75 71 64 78
27.25 72 80 83 79
27.3 66 84 57 92
27.35 58 83 56 82
27.4 67 67 51 82
27.45 73 91 54 83
27.5 74 82 67 89
27.55 84 87 68 79
27.6 80 79 73 101
27.65 82 58 70 100
27.7 70 85 62 96
27.75 71 65 76 85
27.8 70 73 68 71
27.85 76 81 55 89
27.9 73 65 58 91
27.95 85 75 65 95
28 82 77 64 79
28.05 75 89 64 74
28.1 70 85 60 88
28.15 85 73 55 96
28.2 80 94 71 86
28.25 96 84 94 114
28.3 126 101 99 130
28.35 173 172 136 133
28.4 219 257 164 189
28.45 270 213 188 258
28.5 214 230 153 232
28.55 158 139 127 192
28.6 105 110 80 171
28.65 78 84 75 122
28.7 75 72 56 112
28.75 82 79 66 97
28.8 83 69 66 97
28.85 74 63 79 81
28.9 79 65 64 93
28.95 77 80 71 77
29 61 55 62 89
29.05 75 71 64 93
29.1 75 81 69 91
29.15 65 93 78 90
29.2 69 75 63 80
29.25 79 86 60 74
29.3 68 89 64 80
29.35 78 73 78 83
29.4 74 73 66 78
29.45 57 88 72 92
29.5 75 63 79 99
29.55 65 70 79 73
29.6 69 87 69 103
29.65 83 75 48 86
29.7 72 72 59 92
29.75 69 60 68 77
29.8 65 66 58 93
29.85 68 82 74 89
29.9 89 76 75 78
29.95 79 69 73 100
30 84 76 73 108
30.05 110 86 84 101
30.1 129 129 102 124
30.15 146 140 114 154
30.2 150 159 127 186
30.25 136 152 124 157
30.3 117 101 88 169
30.35 81 94 77 125
30.4 72 76 77 120
30.45 85 86 69 116
30.5 75 96 78 91
30.55 71 66 61 64
30.6 70 76 61 92
30.65 72 65 74 97
30.7 87 78 53 84
30.75 67 59 64 92
30.8 71 71 81 82
30.85 75 74 72 79
30.9 80 89 81 56
30.95 76 68 67 87
31 78 68 62 80
31.05 72 72 69 65
31.1 66 69 61 82
31.15 85 72 64 80
31.2 61 67 72 75
31.25 62 73 70 79
31.3 69 60 64 73
31.35 75 74 59 77
31.4 51 69 58 76
31.45 48 59 58 75
31.5 55 73 71 76
31.55 77 77 67 64
31.6 66 66 64 90
31.65 84 74 74 81
31.7 64 71 78 88
31.75 69 79 64 85
31.8 74 79 56 65
31.85 53 67 72 72
31.9 77 57 55 68
31.95 68 66 72 89
32 74 74 80 80
32.05 53 82 61 77
32.1 67 63 66 74
32.15 61 72 67 77
32.2 68 56 66 75
32.25 77 74 48 87
32.3 62 71 60 75
32.35 57 38 63 79
32.4 62 62 78 72
32.45 62 59 70 73
32.5 62 69 63 70
32.55 66 71 56 75
32.6 56 66 65 70
32.65 55 71 52 80
32.7 62 69 62 79
32.75 61 75 68 75
32.8 67 76 66 66
32.85 74 66 63 71
32.9 49 87 78 83
32.95 66 64 71 65
33 82 75 74 86
33.05 57 50 74 88
33.1 59 68 60 77
33.15 61 73 66 77
33.2 62 62 82 70
33.25 74 67 62 85
33.3 60 71 76 72
33.35 72 63 52 70
33.4 66 56 66 77
33.45 71 64 55 74
33.5 58 61 42 66
33.55 66 58 52 79
33.6 59 53 52 69
33.65 66 60 46 76
33.7 53 73 51 84
33.75 70 65 66 71
33.8 52 52 49 73
33.85 66 66 86 74
33.9 58 78 62 82
33.95 65 65 63 87
34 47 53 62 75
34.05 51 63 60 80
34.1 56 77 53 74
34.15 55 53 64 69
34.2 77 49 53 63
34.25 70 82 61 86
34.3 64 69 52 52
34.35 59 67 51 73
34.4 62 77 70 71
34.45 51 58 73 65
34.5 62 78 65 55
34.55 48 69 66 74
34.6 45 70 52 66
34.65 59 72 68 77
34.7 65 62 56 69
34.75 64 68 58 64
34.8 83 73 78 75
34.85 75 112 74 88
34.9 125 136 92 95
34.95 149 139 104 120
35 152 129 103 125
35.05 120 142 97 140
35.1 84 104 80 104
35.15 76 66 76 94
35.2 70 84 70 99
35.25 63 67 60 74
35.3 68 60 62 88
35.35 51 70 52 78
35.4 64 57 62 63
35.45 62 56 43 66
35.5 58 71 63 62
35.55 63 66 57 80
35.6 67 53 57 63
35.65 68 56 59 61
35.7 62 49 46 67
35.75 58 55 66 82
35.8 59 49 49 63
35.85 48 70 57 73
35.9 53 45 47 58
35.95 55 64 43 72
36 54 52 46 71
36.05 56 68 51 74
36.1 49 59 62 96
36.15 53 56 49 93
36.2 66 57 59 92
36.25 60 60 49 99
36.3 63 62 52 113
36.35 61 59 57 102
36.4 48 61 51 107
36.45 67 53 45 81
36.5 61 59 65 84
36.55 50 62 42 101
36.6 48 57 51 72
36.65 46 67 59 66
36.7 70 63 54 86
36.75 54 61 55 61
36.8 62 63 40 61
36.85 62 52 60 51
36.9 45 69 43 77
36.95 56 59 45 71
37 44 73 50 72
37.05 59 58 53 64
37.1 58 42 42 48
37.15 53 52 53 57
37.2 49 64 51 52
37.25 49 54 45 54
37.3 54 56 56 62
37.35 51 50 64 64
37.4 48 68 44 67
37.45 49 58 46 61
37.5 56 45 63 64
37.55 47 51 37 55
37.6 53 60 51 79
37.65 50 46 45 69
37.7 47 45 44 60
37.75 48 45 53 68
37.8 64 60 46 65
37.85 61 45 41 71
37.9 56 57 45 66
37.95 44 54 55 70
38 44 43 51 72
38.05 43 52 48 73
38.1 45 52 46 48
38.15 51 57 34 66
38.2 61 59 50 70
38.25 48 57 53 65
38.3 39 51 46 62
38.35 58 48 43 58
38.4 50 57 45 71
38.45 56 57 55 70
38.5 49 54 45 59
38.55 54 49 65 85
38.6 47 47 48 60
38.65 47 49 65 78
38.7 46 45 54 73
38.75 49 55 56 78
38.8 43 50 51 64
38.85 50 51 46 79
38.9 51 51 45 75
38.95 60 44 50 56
39 69 51 64 60
39.05 46 49 46 61
39.1 68 47 42 78
39.15 44 61 44 79
39.2 42 39 46 66
39.25 46 48 45 72
39.3 52 55 48 75
39.35 43 62 44 65
39.4 46 55 47 60
39.45 52 55 48 78
39.5 57 49 50 68
39.55 46 58 54 68
39.6 48 51 41 80
39.65 47 53 53 81
39.7 51 48 43 78
39.75 61 57 51 78
39.8 48 55 45 83
39.85 53 43 64 80
39.9 59 52 55 77
39.95 46 47 46 69
40 53 57 38 83
40.05 51 48 51 79
40.1 49 50 47 66
40.15 56 40 48 71
40.2 49 62 51 91
40.25 50 65 52 91
40.3 52 72 56 87
40.35 58 61 64 109
40.4 62 63 95 83
40.45 99 89 84 105
40.5 119 127 112 112
40.55 161 160 161 185
40.6 135 183 185 206
40.65 163 176 168 220
40.7 130 158 136 213
40.75 105 119 107 190
40.8 80 80 57 168
40.85 68 67 66 125
40.9 53 71 42 110
40.95 55 65 48 100
41 53 48 58 91
41.05 54 53 52 83
41.1 59 50 53 73
41.15 56 56 59 71
41.2 53 57 56 72
41.25 52 49 50 69
41.3 46 51 46 65
41.35 47 56 45 73
41.4 44 46 60 75
41.45 57 56 55 69
41.5 49 47 31 72
41.55 48 45 50 74
41.6 42 54 50 83
41.65 45 59 56 76
41.7 46 44 39 76
41.75 48 53 47 69
41.8 44 62 51 56
41.85 51 51 44 74
41.9 45 57 38 85
41.95 54 44 39 81
42 44 61 46 72
42.05 46 52 41 72
42.1 43 53 35 90
42.15 53 50 50 73
42.2 50 49 58 88
42.25 38 41 55 82
42.3 42 51 46 61
42.35 51 33 42 77
42.4 51 51 59 59
42.45 42 35 46 80
42.5 36 45 44 80
42.55 36 39 47 76
42.6 53 46 66 76
42.65 44 45 50 79
42.7 38 41 43 76
42.75 45 34 31 63
42.8 55 58 50 84
42.85 33 46 42 78
42.9 50 46 43 70
42.95 58 55 58 66
43 48 48 52 72
43.05 46 61 65 81
43.1 51 47 41 77
43.15 44 57 40 74
43.2 58 63 41 80
43.25 47 47 45 73
43.3 47 38 47 79
43.35 59 43 49 70
43.4 42 53 33 78
43.45 50 43 43 59
43.5 50 51 67 62
43.55 45 45 52 89
43.6 48 48 57 74
43.65 51 57 38 62
43.7 38 37 42 84
43.75 51 63 47 80
43.8 57 44 50 93
43.85 49 50 45 93
43.9 59 54 37 93
43.95 40 48 34 77
44 41 63 39 87
44.05 39 50 56 75
44.1 37 49 53 90
44.15 43 49 48 59
44.2 43 59 52 60
44.25 52 60 41 78
44.3 50 44 52 71
44.35 46 47 49 70
44.4 41 44 37 65
44.45 48 45 47 55
44.5 44 46 44 78
44.55 40 42 33 76
44.6 47 58 40 64
44.65 39 49 51 64
44.7 49 48 42 74
44.75 49 62 47 65
44.8 44 48 49 61
44.85 38 53 46 73
44.9 44 41 37 59
44.95 53 47 32 60
45 46 39 44 62
45.05 51 52 32 62
45.1 31 42 49 63
45.15 38 49 41 66
45.2 51 57 46 63
45.25 42 46 38 60
45.3 47 53 46 59
45.35 46 49 45 64
45.4 37 59 45 61
45.45 66 40 46 62
45.5 53 53 45 67
45.55 40 52 36 63
45.6 45 56 48 62
45.65 39 49 42 62
45.7 47 39 45 71
45.75 39 41 54 58
45.8 45 52 42 66
45.85 38 50 38 57
45.9 48 55 43 56
45.95 42 55 45 52
46 35 49 30 59
46.05 46 57 53 58
46.1 45 41 37 60
46.15 34 39 44 55
46.2 55 45 44 65
46.25 39 53 39 63
46.3 35 52 53 61
46.35 50 38 43 55
46.4 32 47 27 67
46.45 49 45 53 49
46.5 50 49 50 59
46.55 36 56 42 70
46.6 46 44 49 54
46.65 51 56 42 64
46.7 41 50 37 63
46.75 41 54 45 55
46.8 53 43 49 51
46.85 54 51 55 54
46.9 50 55 22 64
46.95 43 51 35 58
47 44 47 39 57
47.05 61 57 31 60
47.1 36 43 35 61
47.15 43 42 49 77
47.2 48 49 48 59
47.25 38 41 47 71
47.3 46 49 39 70
47.35 48 59 36 66
47.4 51 40 30 47
47.45 42 42 39 72
47.5 51 55 43 65
47.55 37 36 44 64
47.6 40 49 51 64
47.65 49 41 40 48
47.7 33 41 50 60
47.75 36 46 44 60
47.8 41 51 50 64
47.85 49 48 54 76
47.9 39 39 45 64
47.95 42 53 50 52
48 58 58 38 41
48.05 51 37 51 60
48.1 43 40 51 76
48.15 48 46 50 51
48.2 46 49 42 55
48.25 34 58 37 45
48.3 44 49 26 66
48.35 39 63 54 68
48.4 44 48 47 61
48.45 46 48 46 61
48.5 35 49 36 63
48.55 35 46 39 61
48.6 51 48 44 55
48.65 43 61 53 52
48.7 45 61 50 51
48.75 54 38 45 53
48.8 48 59 52 69
48.85 41 60 50 68
48.9 49 50 41 54
48.95 52 52 49 62
49 36 51 42 59
49.05 42 58 48 57
49.1 38 43 41 44
49.15 44 57 51 56
49.2 44 46 45 71
49.25 38 57 41 58
49.3 49 57 28 69
49.35 54 39 44 63
49.4 52 54 52 50
49.45 39 56 45 59
49.5 41 51 58 58
49.55 66 58 63 57
49.6 51 44 58 76
49.65 38 51 50 54
49.7 34 60 52 55
49.75 52 51 51 47
49.8 46 51 53 53
49.85 60 55 52 51
49.9 47 47 55 54
49.95 45 54 39 57
50 68 73 58 55
50.05 66 86 50 70
50.1 68 87 79 78
50.15 89 98 114 75
50.2 133 156 143 105
50.25 137 152 160 169
50.3 125 162 185 162
50.35 124 141 121 132
50.4 103 113 105 127
50.45 88 78 77 118
50.5 72 74 66 72
50.55 59 65 54 60
50.6 56 57 55 62
50.65 46 46 56 58
50.7 39 53 45 57
50.75 51 57 57 53
50.8 27 58 41 52
50.85 45 53 34 62
50.9 41 54 60 50
50.95 43 55 40 47
51 51 49 52 68
51.05 49 51 47 51
51.1 45 64 54 51
51.15 38 48 52 51
51.2 48 43 48 50
51.25 43 57 37 59
51.3 42 40 54 55
51.35 44 39 63 57
51.4 45 50 41 46
51.45 49 44 58 52
51.5 40 51 56 57
51.55 43 40 56 59
51.6 37 42 42 72
51.65 50 47 53 47
51.7 47 43 48 61
51.75 37 57 44 60
51.8 39 59 46 65
51.85 43 62 42 70
51.9 42 47 41 60
51.95 40 51 41 65
52 45 45 64 56
52.05 34 44 58 61
52.1 32 43 70 62
52.15 43 49 58 62
52.2 37 50 47 66
52.25 47 52 43 82
52.3 62 42 58 62
52.35 36 49 54 62
52.4 45 44 41 67
52.45 36 48 37 68
52.5 37 48 52 65
52.55 38 46 50 63
52.6 37 47 59 62
52.65 35 43 45 56
52.7 38 52 49 69
52.75 47 47 47 66
52.8 40 38 47 67
52.85 50 54 47 62
52.9 50 50 38 56
52.95 44 40 54 59
53 44 58 30 63
53.05 35 56 54 53
53.1 46 43 48 43
53.15 43 49 52 57
53.2 40 40 40 56
53.25 57 47 47 63
53.3 29 45 38 57
53.35 39 49 56 63
53.4 39 38 50 66
53.45 43 44 48 64
53.5 51 52 43 65
53.55 44 61 42 51
53.6 53 59 45 63
53.65 40 57 50 62
53.7 41 56 47 50
53.75 59 23 47 66
53.8 46 47 35 57
53.85 46 42 47 67
53.9 57 60 42 53
53.95 52 43 50 62
54 48 52 44 60
54.05 50 50 31 57
54.1 40 50 54 55
54.15 42 45 43 38
54.2 46 52 47 59
54.25 48 45 40 54
54.3 47 42 44 49
54.35 42 45 47 53
54.4 49 48 47 55
54.45 43 42 48 54
54.5 43 50 49 54
54.55 54 45 41 57
54.6 44 53 42 59
54.65 40 47 41 45
54.7 45 35 49 58
54.75 34 37 47 52
54.8 42 53 45 48
54.85 40 58 41 56
54.9 34 50 47 51
54.95 43 42 37 53
55 51 51 59 63
55.05 56 55 48 55
55.1 42 37 42 39
55.15 37 48 39 67
55.2 41 52 41 61
55.25 49 52 47 61
55.3 53 39 40 71
55.35 46 51 40 61
55.4 47 51 44 53
55.45 39 43 34 57
55.5 43 49 54 57
55.55 43 40 40 58
55.6 41 37 56 57
55.65 38 50 41 56
55.7 36 51 35 56
55.75 55 47 43 62
55.8 45 51 45 59
55.85 37 56 40 45
55.9 47 47 45 54
55.95 50 36 44 44
56 46 44 54 52
56.05 51 47 43 58
56.1 51 48 45 53
56.15 56 42 32 65
56.2 31 43 46 63
56.25 44 53 47 47
56.3 41 35 35 54
56.35 45 49 43 55
56.4 45 47 34 54
56.45 49 44 40 56
56.5 45 45 49 59
56.55 60 61 59 65
56.6 30 52 53 50
56.65 38 51 46 57
56.7 51 54 53 39
56.75 54 54 46 36
56.8 45 39 51 63
56.85 38 55 45 57
56.9 40 57 43 56
56.95 41 38 45 58
57 36 42 37 69
57.05 35 60 45 49
57.1 45 47 38 48
57.15 41 39 46 47
57.2 49 51 42 67
57.25 36 42 29 51
57.3 38 40 29 52
57.35 43 47 45 53
57.4 43 62 32 57
57.45 41 41 45 69
57.5 42 54 39 53
57.55 42 52 30 65
57.6 41 40 47 71
57.65 39 42 45 49
57.7 37 52 53 56
57.75 48 58 38 44
57.8 42 54 51 53
57.85 56 47 35 47
57.9 45 41 30 46
57.95 39 44 54 59
58 51 32 40 53
58.05 40 39 41 60
58.1 47 47 33 41
58.15 39 46 40 59
58.2 46 51 51 41
58.25 37 52 48 58
58.3 41 37 45 49
58.35 36 48 43 44
58.4 50 44 45 54
58.45 42 45 44 41
58.5 58 56 47 58
58.55 36 51 48 52
58.6 59 54 57 74
58.65 57 63 60 72
58.7 57 75 65 68
58.75 68 74 81 79
58.8 61 60 53 77
58.85 68 74 62 94
58.9 58 67 53 67
58.95 54 44 42 67
59 53 39 42 71
59.05 59 47 39 63
59.1 48 38 45 55
59.15 49 48 57 49
59.2 42 52 49 46
59.25 49 41 45 54
59.3 45 52 41 46
59.35 38 48 50 47
59.4 44 50 38 51
59.45 54 55 61 57
59.5 37 49 54 59
59.55 52 66 62 61
59.6 62 65 54 57
59.65 70 87 82 79
59.7 73 97 82 74
59.75 88 87 79 84
59.8 69 97 61 83
59.85 62 71 67 67
59.9 60 55 72 78
59.95 51 56 44 60
60 59 59 52 51
60.05 51 48 57 48
60.1 45 54 48 55
60.15 45 49 38 53
60.2 39 45 45 50
60.25 55 43 39 60
60.3 48 40 38 52
60.35 45 40 55 51
60.4 34 44 35 59
60.45 47 38 39 49
60.5 32 48 53 44
60.55 40 41 51 36
60.6 40 44 36 55
60.65 54 44 55 55
60.7 35 46 29 49
60.75 50 47 37 46
60.8 40 45 40 68
60.85 34 51 54 48
60.9 39 40 63 50
60.95 31 58 39 46
61 27 46 37 43
61.05 45 55 47 46
61.1 47 42 52 48
61.15 41 45 42 60
61.2 34 43 49 47
61.25 46 40 47 57
61.3 42 43 35 51
61.35 33 46 37 62
61.4 45 39 54 50
61.45 41 54 58 56
61.5 31 48 57 49
61.55 42 44 47 49
61.6 40 52 37 52
61.65 32 48 42 76
61.7 35 36 48 59
61.75 33 51 28 46
61.8 45 47 42 50
61.85 48 48 40 55
61.9 50 37 40 41
61.95 44 50 39 41
62 36 31 48 51
62.05 34 51 38 28
62.1 44 48 40 48
62.15 47 43 43 52
62.2 40 45 40 58
62.25 42 40 47 60
62.3 50 35 44 51
62.35 51 57 41 56
62.4 43 58 52 70
62.45 46 51 55 38
62.5 59 64 58 65
62.55 50 52 47 53
62.6 56 72 62 61
62.65 63 57 57 68
62.7 67 68 55 83
62.75 54 72 60 61
62.8 61 57 54 67
62.85 54 53 53 55
62.9 43 50 49 66
62.95 44 55 50 49
63 36 55 45 63
63.05 49 53 46 47
63.1 41 40 42 51
63.15 46 41 47 40
63.2 44 33 51 58
63.25 36 45 43 46
63.3 34 49 46 58
63.35 36 42 40 46
63.4 58 62 37 57
63.45 42 51 40 58
63.5 40 54 36 40
63.55 48 52 51 46
63.6 43 39 41 46
63.65 35 50 51 46
63.7 36 39 42 47
63.75 42 51 36 52
63.8 41 43 54 52
63.85 40 53 42 37
63.9 39 51 51 63
63.95 40 59 42 66
64 32 44 32 43
64.05 46 57 39 53
64.1 44 42 38 68
64.15 41 44 57 51
64.2 44 41 41 50
64.25 35 40 30 61
64.3 45 51 36 41
64.35 46 52 44 42
64.4 37 47 44 51
64.45 43 52 46 41
64.5 36 35 47 63
64.55 40 61 41 59
64.6 36 40 40 49
64.65 45 38 53 58
64.7 38 41 44 50
64.75 42 49 44 43
64.8 37 53 42 41
64.85 39 47 42 55
64.9 50 42 35 53
64.95 40 41 43 45
65 28 43 48 46
65.05 34 38 39 42
65.1 41 44 44 45
65.15 42 54 43 49
65.2 40 38 46 33
65.25 45 45 44 54
65.3 34 46 33 48
65.35 44 41 29 32
65.4 49 41 55 46
65.45 49 45 43 58
65.5 46 40 38 56
65.55 36 44 51 50
65.6 40 48 44 45
65.65 51 32 44 38
65.7 30 35 29 42
65.75 48 60 42 64
65.8 34 55 38 44
65.85 52 43 48 56
65.9 32 47 46 56
65.95 43 60 47 50
66 41 44 40 47
66.05 42 51 34 56
66.1 61 49 44 53
66.15 57 57 45 42
66.2 55 52 50 59
66.25 44 50 42 53
66.3 63 83 63 62
66.35 78 75 85 89
66.4 80 103 120 69
66.45 77 103 96 81
66.5 98 112 114 111
66.55 86 76 85 103
66.6 81 99 80 80
66.65 61 95 64 78
66.7 62 69 65 87
66.75 59 66 50 70
66.8 54 51 44 62
66.85 50 56 38 70
66.9 52 61 45 60
66.95 32 42 46 60
67 35 46 51 57
67.05 39 47 40 46
67.1 47 45 45 52
67.15 39 40 39 53
67.2 51 43 37 46
67.25 53 46 44 53
67.3 35 52 45 48
67.35 41 44 42 50
67.4 38 55 25 49
67.45 25 46 40 45
67.5 48 51 45 54
67.55 41 47 41 46
67.6 37 50 38 44
67.65 45 48 45 53
67.7 37 44 39 51
67.75 29 42 61 66
67.8 32 52 45 51
67.85 28 52 46 48
67.9 31 54 35 58
67.95 41 48 46 45
68 33 37 39 45
68.05 44 36 35 52
68.1 48 41 46 52
68.15 39 55 41 64
68.2 46 51 46 47
68.25 49 31 49 50
68.3 39 53 36 47
68.35 40 41 38 48
68.4 50 61 60 44
68.45 40 31 39 55
68.5 54 37 41 33
68.55 44 43 46 51
68.6 35 48 51 54
68.65 31 51 37 55
68.7 46 40 47 52
68.75 28 58 40 44
68.8 38 52 41 56
68.85 29 50 37 50
68.9 34 47 44 46
68.95 43 45 45 53
69 49 42 42 50
69.05 37 51 61 35
69.1 43 41 54 42
69.15 44 40 48 59
69.2 31 35 41 49
69.25 33 49 35 56
69.3 43 52 49 46
69.35 47 56 44 34
69.4 42 47 29 51
69.45 39 51 46 41
69.5 37 36 30 51
69.55 35 42 50 35
69.6 42 47 40 43
69.65 44 45 40 46
69.7 37 48 31 41
69.75 53 47 34 50
69.8 24 49 41 41
69.85 35 33 49 40
69.9 41 32 34 53
69.95 34 37 33 49
70 42 31 29 39
70.05 37 35 35 38
70.1 22 47 31 49
70.15 47 47 37 40
70.2 35 47 42 50
70.25 31 31 34 39
70.3 52 38 35 46
70.35 37 54 38 49
70.4 41 45 41 43
70.45 40 34 37 49
70.5 47 42 41 48
70.55 44 49 42 41
70.6 39 49 50 46
70.65 47 39 35 54
70.7 30 49 34 51
70.75 39 52 40 43
70.8 41 40 32 41
70.85 36 37 32 40
70.9 25 52 45 44
70.95 41 30 47 40
71 33 38 33 58
71.05 35 53 34 34
71.1 32 36 36 53
71.15 35 57 54 45
71.2 38 47 32 39
71.25 45 52 32 59
71.3 45 45 39 43
71.35 57 37 38 42
71.4 41 43 34 49
71.45 30 48 44 48
71.5 28 41 34 45
71.55 34 47 45 42
71.6 42 39 41 43
71.65 41 52 44 57
71.7 32 46 43 51
71.75 25 44 36 48
71.8 43 49 39 45
71.85 45 61 42 41
71.9 33 40 43 57
71.95 34 39 34 42
72 44 42 37 53
72.05 43 44 40 47
72.1 45 38 43 48
72.15 42 37 37 48
72.2 42 41 43 46
72.25 30 36 39 41
72.3 44 40 37 47
72.35 47 34 45 49
72.4 36 54 33 52
72.45 45 42 42 37
72.5 40 38 36 37
72.55 45 54 45 56
72.6 33 55 37 57
72.65 39 47 27 41
72.7 47 39 40 52
72.75 39 30 45 41
72.8 40 39 30 45
72.85 34 56 46 52
72.9 39 39 43 42
72.95 30 48 32 55
73 31 39 27 49
73.05 37 42 40 39
73.1 35 39 42 42
73.15 39 41 45 53
73.2 37 46 36 55
73.25 34 44 46 51
73.3 38 48 32 51
73.35 41 38 48 44
73.4 34 44 36 38
73.45 50 50 45 63
73.5 46 48 49 63
73.55 44 55 54 63
73.6 54 79 45 60
73.65 57 71 77 66
73.7 81 95 79 66
73.75 71 104 103 102
73.8 83 89 78 84
73.85 80 96 77 99
73.9 70 72 64 83
73.95 50 85 66 89
74 61 71 59 78
74.05 39 76 62 79
74.1 58 58 50 71
74.15 46 52 39 66
74.2 33 48 42 72
74.25 40 55 46 59
74.3 41 41 42 47
74.35 38 46 40 44
74.4 48 40 38 39
74.45 49 48 51 44
74.5 46 44 45 52
74.55 39 44 44 61
74.6 46 42 40 48
74.65 43 39 48 44
74.7 31 44 37 52
74.75 37 53 36 56
74.8 32 49 38 58
74.85 32 42 33 39
74.9 44 43 43 39
74.95 34 49 40 46
75 29 45 37 55
75.05 31 43 35 39
75.1 33 46 36 42
75.15 52 28 43 44
75.2 32 49 41 54
75.25 29 38 41 43
75.3 29 39 41 51
75.35 36 44 34 48
75.4 28 49 40 43
75.45 28 43 42 45
75.5 45 40 38 49
75.55 25 53 35 49
75.6 30 51 35 42
75.65 26 47 45 46
75.7 32 46 44 47
75.75 32 44 33 49
75.8 44 50 35 63
75.85 40 44 39 42
75.9 30 41 44 45
75.95 34 48 34 58
76 44 49 36 60
76.05 41 57 37 50
76.1 46 41 39 49
76.15 30 39 32 49
76.2 39 34 34 70
76.25 38 49 34 43
76.3 43 33 33 42
76.35 30 50 39 55
76.4 47 55 33 44
76.45 31 33 37 46
76.5 34 40 37 35
76.55 36 47 34 51
76.6 45 38 50 51
76.65 36 41 34 41
76.7 32 40 36 46
76.75 30 41 44 38
76.8 34 52 43 43
76.85 37 37 36 51
76.9 37 51 43 48
76.95 41 46 40 52
77 37 54 33 54
77.05 30 44 55 44
77.1 40 46 42 49
77.15 47 40 41 40
77.2 34 44 30 60
77.25 44 52 45 49
77.3 35 48 36 36
77.35 41 35 33 47
77.4 33 43 34 51
77.45 36 42 48 56
77.5 29 36 37 53
77.55 38 47 36 51
77.6 32 37 48 41
77.65 45 49 33 56
77.7 34 42 39 43
77.75 29 45 51 51
77.8 36 43 36 41
77.85 33 43 35 46
77.9 35 46 37 50
77.95 34 39 46 40
78 40 35 36 43
78.05 43 37 44 54
78.1 33 55 43 49
78.15 35 42 27 41
78.2 40 51 46 38
78.25 43 47 41 36
78.3 38 32 37 31
78.35 38 44 44 56
78.4 43 33 41 50
78.45 40 45 37 41
78.5 42 35 32 36
78.55 38 39 38 43
78.6 34 48 43 39
78.65 34 33 36 58
78.7 40 28 36 43
78.75 37 59 41 60
78.8 37 47 51 46
78.85 39 30 39 47
78.9 47 46 41 42
78.95 40 42 34 52
79 35 35 40 33
79.05 34 40 42 42
79.1 40 40 49 49
79.15 39 48 39 52
79.2 33 30 41 43
79.25 38 40 50 60
79.3 32 44 34 46
79.35 48 48 26 47
79.4 39 34 45 48
79.45 35 51 39 51
79.5 37 39 32 36
79.55 32 45 38 46
79.6 40 57 37 51
79.65 36 45 44 46
79.7 40 30 53 50
79.75 40 46 33 45
79.8 26 37 44 54
79.85 39 38 30 58
79.9 49 37 35 47
79.95 36 30 31 43
80 43 38 41 45
My code is as given below
set terminal postscript eps enhanced colour font 'Times-Roman,12' size 5in,8in
set output "XRD_P3.eps"
##
set style line 1 lt 1 lw 1 lc rgb "black"
set xtics out scale 1.5
set ytics out scale 1.5
set format y ''
set tics font ",16"
set xlabel "2{/Symbol \161} (deg.)" font ",16"
set ylabel "Intensity (a.u.)" font ",16"
set key inside right top
set multiplot layout 4,1 rowsfirst
##
set yrange [0:1500]
set key title "LiCl-KCl + 6 wt.% H_{2}O" font ",14"
##
set label 1 '(111)' font ",12" at 24.10, 482 point pt 7 ps 1.75 lt rgb "red" offset -0.50, 0.50 rotate by 90
set label 2 '(200)' font ",12" at 28.45, 268 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
set label 3 '(220)' font ",12" at 40.65, 230 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
set label 4 '(400)' font ",12" at 58.85, 104 point pt 7 ps 1.75 lt rgb "red" offset -1.00,0.50 rotate by 90
set label 5 '(420)' font ",12" at 66.50, 121 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
##
set label 6 '(111)' font ",12" at 30.20, 196 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 7 '(200)' font ",12" at 35.05, 150 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 8 '(220)' font ",12" at 50.25, 179 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 9 '(311)' font ",12" at 59.75, 94 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 11 '(400)' font ",12" at 73.75, 112 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
##
set label 12 '(101)' font ",12" at 21.70, 1116 point pt 7 ps 1.75 lt rgb "#006400" offset -0.50,0.50 rotate by 90
##
set label 13 'LiCl' font ",14" at 72, 1200 point pt 7 ps 1.75 lt rgb "blue" offset 2,-0.10
set label 14 'KCl' font ",14" at 72, 1100 point pt 7 ps 1.75 lt rgb "red" offset 2,-0.10
set label 15 'LiClO_{4}' font ",14" at 72, 1000 point pt 7 ps 1.75 lt rgb "#006400" offset 2,-0.10
##
plot [10:80] 'XRD_P3.dat' u 1:5 w l ls 1 notitle
##
##
set yrange [0:300]
set key title "LiCl-KCl (Vacuum dried)" font ",14"
##
set label 1 '(222)' font ",12" at 50.30, 195 point pt 7 ps 1.75 lt rgb "red" offset -0.50, 0.50 rotate by 90
set label 2 '(200)' font ",12" at 28.45, 198 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
set label 3 '(220)' font ",12" at 40.60, 195 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
set label 4 '(400)' font ",12" at 58.75, 91 point pt 7 ps 1.75 lt rgb "red" offset -1.00,0.50 rotate by 90
set label 5 '(420)' font ",12" at 66.40, 130 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
##
set label 6 '(111)' font ",12" at 30.20, 137 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 7 '(200)' font ",12" at 34.95, 114 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 9 '(311)' font ",12" at 59.65, 92 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 10 '(222)' font ",12" at 62.75, 70 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 11 '(400)' font ",12" at 73.75, 113 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
##
set label 12 'LiCl' font ",14" at 72, 250 point pt 7 ps 1.75 lt rgb "blue" offset 2,-0.10
set label 13 'KCl' font ",14" at 72, 220 point pt 7 ps 1.75 lt rgb "red" offset 2,-0.10
##
plot [10:80] 'XRD_P3.dat' u 1:4 w l ls 1 notitle
##
##
set yrange [0:350]
set key title "LiCl-KCl (Chlorinated)" font ",14"
##
set label 2 '(200)' font ",12" at 28.40, 267 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
set label 3 '(220)' font ",12" at 40.60, 193 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
set label 4 '(400)' font ",12" at 58.70, 85 point pt 7 ps 1.75 lt rgb "red" offset -1.00,0.50 rotate by 90
set label 5 '(420)' font ",12" at 66.50, 122 point pt 7 ps 1.75 lt rgb "red" offset -0.50,0.50 rotate by 90
##
set label 6 '(111)' font ",12" at 30.20, 169 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 7 '(200)' font ",12" at 35.05, 152 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 8 '(220)' font ",12" at 50.30, 172 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 9 '(311)' font ",12" at 59.80, 107 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 10 '(222)' font ",12" at 62.60, 82 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
set label 11 '(400)' font ",12" at 73.75, 114 point pt 7 ps 1.75 lt rgb "blue" offset -0.50,0.50 rotate by 90
##
set label 12 'LiCl' font ",14" at 72, 300 point pt 7 ps 1.75 lt rgb "blue" offset 2,-0.10
set label 13 'KCl' font ",14" at 72, 270 point pt 7 ps 1.75 lt rgb "red" offset 2,-0.10
##
plot [10:80] 'XRD_P3.dat' u 1:3 w l ls 1 notitle
##
##
unset multiplot
In the plot, there are random texts appearing outside the XRD patterns, and in some cases the labels are rotated. PNG version of the plot is attached.
The definition of labels persists in a multiplot environment. It's somewhere in the documentation but I haven't found it right away in help label.
Here is some code to illustrate your "problem".
In the second plot label 4 and label 5 are not defined explicitely, but the definition still exists in memory from the first plot. Hence, label 4 and label 5 will be drawn at the second plot's coordinates 4,4 and 5,5 which are located somewhere in the first plot.
So, either you explicitly unset them unset label 4 and unset label 5 or you unset all labels unset label and newly define all desired labels.
Code:
### setting/unsetting of labels
reset session
set xrange [0:8]
set multiplot layout 2,1
set label 1 at 1,1 "Label1a"
set label 2 at 2,2 "Label2a"
set label 3 at 3,3 "Label3a"
set label 4 at 4,4 "Label4a"
set label 5 at 5,5 "Label5a"
plot x
# unset label # uncomment this line to reset all labels
set label 1 at 1,-1 "Label1b"
set label 2 at 2,-2 "Label2b"
set label 3 at 3,-3 "Label3b"
plot -x
unset multiplot
### end of code
Result:
I have an input file 'input.dat':
08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08
49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00
81 49 31 73 55 79 14 29 93 71 40 67 53 88 30 03 49 13 36 65
52 70 95 23 04 60 11 42 69 24 68 56 01 32 56 71 37 02 36 91
22 31 16 71 51 67 63 89 41 92 36 54 22 40 40 28 66 33 13 80
24 47 32 60 99 03 45 02 44 75 33 53 78 36 84 20 35 17 12 50
32 98 81 28 64 23 67 10 26 38 40 67 59 54 70 66 18 38 64 70
67 26 20 68 02 62 12 20 95 63 94 39 63 08 40 91 66 49 94 21
24 55 58 05 66 73 99 26 97 17 78 78 96 83 14 88 34 89 63 72
21 36 23 09 75 00 76 44 20 45 35 14 00 61 33 97 34 31 33 95
78 17 53 28 22 75 31 67 15 94 03 80 04 62 16 14 09 53 56 92
16 39 05 42 96 35 31 47 55 58 88 24 00 17 54 24 36 29 85 57
86 56 00 48 35 71 89 07 05 44 44 37 44 60 21 58 51 54 17 58
19 80 81 68 05 94 47 69 28 73 92 13 86 52 17 77 04 89 55 40
04 52 08 83 97 35 99 16 07 97 57 32 16 26 26 79 33 27 98 66
88 36 68 87 57 62 20 72 03 46 33 67 46 55 12 32 63 93 53 69
04 42 16 73 38 25 39 11 24 94 72 18 08 46 29 32 40 62 76 36
20 69 36 41 72 30 23 88 34 62 99 69 82 67 59 85 74 04 36 16
20 73 35 29 78 31 90 01 74 31 49 71 48 86 81 16 23 57 05 54
01 70 54 71 83 51 54 69 16 92 33 48 61 43 52 01 89 19 67 48
I store the data in a 2D array and try to process as in the given code:
if __name__ == "__main__":
dataFile = open("/Users/atulyaratanjha/Documents/Python/P11.dat")
arr = []
for line in dataFile:
arr.append(line.split())
maxMult = 0
for i in range(16):
for j in range(20):
mult = arr[i][j] * arr[i+1][j] * arr[i+2][j] * arr[i+3][j]
maxMult = max(maxMult, mult)
for i in range(20):
for j in range(16):
mult = arr[i][j] * arr[i][j+1] * arr[i][j+2] * arr[i][j+3]
maxMult = max(maxMult, mult)
for i in range(16):
for j in range(16):
mult = arr[i][j] * arr[i+1][j+1] * arr[i+2][j+2] * arr[i+2][j+3]
maxMult = max(maxMult, mult)
print(maxMult)
It gives this Error:
TypeError: can't multiply sequence by non-int of type 'str'
I know that I can change the data into 'int' from 'str' by running a for loop, but is there any way to store the data as 'int' at the input stage?
Andrej Kesely explains you might
change the arr.append(line.split()) to arr.append(list(map(int, line.split()))) and it should work.
After running this code. why are all these numbers being printed even though i haven't printed them. I think enumerate returns all these . If yes, then is there any way I can stop these.
def primeOrNot(num):
count = 0
for i in range (num-1, 1, -1):
print(i,num)
if(num%i==0):
count=1
if (count==0):
return True
else: return False
def nearest_prime(num):
nearest = 0
farthest = 0
for i in range(num+1,256):
if primeOrNot(i):
farthest = i
break
for i in range(num-1,1,-1):
if primeOrNot(i):
nearest = i
break
nearest_dist = num - nearest
farthest_dist = farthest - num
if(farthest_dist>nearest_dist):
return nearest
elif (nearest_dist>farthest_dist):
return farthest
elif(nearest_dist==farthest_dist):
return nearest
def main_code(test_case_no):
for tn in range(0,test_case_no):
str_len = input()
input_str = input()
input_list = [ord(i) for i in input_str]
for index,num in enumerate(input_list): #error here
if not primeOrNot(num):
input_list[index]=nearest_prime(num)
ouput_list = [chr(i) for i in input_list]
output_str = "".join(ouput_list)
print(output_str)
test_case_no = int(input())
main_code(test_case_no)
Input:
1
6
AFREEN
Expected output :
CGSCCO
Actual output:-
64 65
63 65
62 65
61 65
60 65
59 65
58 65
57 65
56 65
55 65
54 65
53 65
52 65
51 65
50 65
49 65
48 65
47 65
46 65
45 65
44 65
43 65
42 65
41 65
40 65
39 65
38 65
37 65
36 65
35 65
34 65
33 65
32 65
31 65
30 65
29 65
28 65
27 65
26 65
25 65
24 65
23 65
22 65
21 65
20 65
19 65
18 65
17 65
16 65
15 65
14 65
13 65
12 65
11 65
10 65
9 65
8 65
7 65
6 65
5 65
4 65
3 65
2 65
65 66
64 66
63 66
62 66
61 66
60 66
59 66
58 66
57 66
56 66
55 66
54 66
53 66
52 66
51 66
50 66
49 66
48 66
47 66
46 66
45 66
44 66
43 66
42 66
41 66
40 66
39 66
38 66
37 66
36 66
35 66
34 66
33 66
32 66
31 66
30 66
29 66
28 66
27 66
26 66
25 66
24 66
23 66
22 66
21 66
20 66
19 66
18 66
17 66
16 66
15 66
14 66
13 66
12 66
11 66
10 66
9 66
8 66
7 66
6 66
5 66
4 66
3 66
2 66
66 67
65 67
64 67
63 67
62 67
61 67
60 67
59 67
58 67
57 67
56 67
55 67
54 67
53 67
52 67
51 67
50 67
49 67
48 67
47 67
46 67
45 67
44 67
43 67
42 67
41 67
40 67
39 67
38 67
37 67
36 67
35 67
34 67
33 67
32 67
31 67
30 67
29 67
28 67
27 67
26 67
25 67
24 67
23 67
22 67
21 67
20 67
19 67
18 67
17 67
16 67
15 67
14 67
13 67
12 67
11 67
10 67
9 67
8 67
7 67
6 67
5 67
4 67
3 67
2 67
63 64
62 64
61 64
60 64
59 64
58 64
57 64
56 64
55 64
54 64
53 64
52 64
51 64
50 64
49 64
48 64
47 64
46 64
45 64
44 64
43 64
42 64
41 64
40 64
39 64
38 64
37 64
36 64
35 64
34 64
33 64
32 64
31 64
30 64
29 64
28 64
27 64
26 64
25 64
24 64
23 64
22 64
21 64
20 64
19 64
18 64
17 64
16 64
15 64
14 64
13 64
12 64
11 64
10 64
9 64
8 64
7 64
6 64
5 64
4 64
3 64
2 64
62 63
61 63
60 63
59 63
58 63
57 63
56 63
55 63
54 63
53 63
52 63
51 63
50 63
49 63
48 63
47 63
46 63
45 63
44 63
43 63
42 63
41 63
40 63
39 63
38 63
37 63
36 63
35 63
34 63
33 63
32 63
31 63
30 63
29 63
28 63
27 63
26 63
25 63
24 63
23 63
22 63
21 63
20 63
19 63
18 63
17 63
16 63
15 63
14 63
13 63
12 63
11 63
10 63
9 63
8 63
7 63
6 63
5 63
4 63
3 63
2 63
61 62
60 62
59 62
58 62
57 62
56 62
55 62
54 62
53 62
52 62
51 62
50 62
49 62
48 62
47 62
46 62
45 62
44 62
43 62
42 62
41 62
40 62
39 62
38 62
37 62
36 62
35 62
34 62
33 62
32 62
31 62
30 62
29 62
28 62
27 62
26 62
25 62
24 62
23 62
22 62
21 62
20 62
19 62
18 62
17 62
16 62
15 62
14 62
13 62
12 62
11 62
10 62
9 62
8 62
7 62
6 62
5 62
4 62
3 62
2 62
60 61
59 61
58 61
57 61
56 61
55 61
54 61
53 61
52 61
51 61
50 61
49 61
48 61
47 61
46 61
45 61
44 61
43 61
42 61
41 61
40 61
39 61
38 61
37 61
36 61
35 61
34 61
33 61
32 61
31 61
30 61
29 61
28 61
27 61
26 61
25 61
24 61
23 61
22 61
21 61
20 61
19 61
18 61
17 61
16 61
15 61
14 61
13 61
12 61
11 61
10 61
9 61
8 61
7 61
6 61
5 61
4 61
3 61
2 61
69 70
68 70
67 70
66 70
65 70
64 70
63 70
62 70
61 70
60 70
59 70
58 70
57 70
56 70
55 70
54 70
53 70
52 70
51 70
50 70
49 70
48 70
47 70
46 70
45 70
44 70
43 70
42 70
41 70
40 70
39 70
38 70
37 70
36 70
35 70
34 70
33 70
32 70
31 70
30 70
29 70
28 70
27 70
26 70
25 70
24 70
23 70
22 70
21 70
20 70
19 70
18 70
17 70
16 70
15 70
14 70
13 70
12 70
11 70
10 70
9 70
8 70
7 70
6 70
5 70
4 70
3 70
2 70
70 71
69 71
68 71
67 71
66 71
65 71
64 71
63 71
62 71
61 71
60 71
59 71
58 71
57 71
56 71
55 71
54 71
53 71
52 71
51 71
50 71
49 71
48 71
47 71
46 71
45 71
44 71
43 71
42 71
41 71
40 71
39 71
38 71
37 71
36 71
35 71
34 71
33 71
32 71
31 71
30 71
29 71
28 71
27 71
26 71
25 71
24 71
23 71
22 71
21 71
20 71
19 71
18 71
17 71
16 71
15 71
14 71
13 71
12 71
11 71
10 71
9 71
8 71
7 71
6 71
5 71
4 71
3 71
2 71
68 69
67 69
66 69
65 69
64 69
63 69
62 69
61 69
60 69
59 69
58 69
57 69
56 69
55 69
54 69
53 69
52 69
51 69
50 69
49 69
48 69
47 69
46 69
45 69
44 69
43 69
42 69
41 69
40 69
39 69
38 69
37 69
36 69
35 69
34 69
33 69
32 69
31 69
30 69
29 69
28 69
27 69
26 69
25 69
24 69
23 69
22 69
21 69
20 69
19 69
18 69
17 69
16 69
15 69
14 69
13 69
12 69
11 69
10 69
9 69
8 69
7 69
6 69
5 69
4 69
3 69
2 69
67 68
66 68
65 68
64 68
63 68
62 68
61 68
60 68
59 68
58 68
57 68
56 68
55 68
54 68
53 68
52 68
51 68
50 68
49 68
48 68
47 68
46 68
45 68
44 68
43 68
42 68
41 68
40 68
39 68
38 68
37 68
36 68
35 68
34 68
33 68
32 68
31 68
30 68
29 68
28 68
27 68
26 68
25 68
24 68
23 68
22 68
21 68
20 68
19 68
18 68
17 68
16 68
15 68
14 68
13 68
12 68
11 68
10 68
9 68
8 68
7 68
6 68
5 68
4 68
3 68
2 68
66 67
65 67
64 67
63 67
62 67
61 67
60 67
59 67
58 67
57 67
56 67
55 67
54 67
53 67
52 67
51 67
50 67
49 67
48 67
47 67
46 67
45 67
44 67
43 67
42 67
41 67
40 67
39 67
38 67
37 67
36 67
35 67
34 67
33 67
32 67
31 67
30 67
29 67
28 67
27 67
26 67
25 67
24 67
23 67
22 67
21 67
20 67
19 67
18 67
17 67
16 67
15 67
14 67
13 67
12 67
11 67
10 67
9 67
8 67
7 67
6 67
5 67
4 67
3 67
2 67
81 82
80 82
79 82
78 82
77 82
76 82
75 82
74 82
73 82
72 82
71 82
70 82
69 82
68 82
67 82
66 82
65 82
64 82
63 82
62 82
61 82
60 82
59 82
58 82
57 82
56 82
55 82
54 82
53 82
52 82
51 82
50 82
49 82
48 82
47 82
46 82
45 82
44 82
43 82
42 82
41 82
40 82
39 82
38 82
37 82
36 82
35 82
34 82
33 82
32 82
31 82
30 82
29 82
28 82
27 82
26 82
25 82
24 82
23 82
22 82
21 82
20 82
19 82
18 82
17 82
16 82
15 82
14 82
13 82
12 82
11 82
10 82
9 82
8 82
7 82
6 82
5 82
4 82
3 82
2 82
82 83
81 83
80 83
79 83
78 83
77 83
76 83
75 83
74 83
73 83
72 83
71 83
70 83
69 83
68 83
67 83
66 83
65 83
64 83
63 83
62 83
61 83
60 83
59 83
58 83
57 83
56 83
55 83
54 83
53 83
52 83
51 83
50 83
49 83
48 83
47 83
46 83
45 83
44 83
43 83
42 83
41 83
40 83
39 83
38 83
37 83
36 83
35 83
34 83
33 83
32 83
31 83
30 83
29 83
28 83
27 83
26 83
25 83
24 83
23 83
22 83
21 83
20 83
19 83
18 83
17 83
16 83
15 83
14 83
13 83
12 83
11 83
10 83
9 83
8 83
7 83
6 83
5 83
4 83
3 83
2 83
80 81
79 81
78 81
77 81
76 81
75 81
74 81
73 81
72 81
71 81
70 81
69 81
68 81
67 81
66 81
65 81
64 81
63 81
62 81
61 81
60 81
59 81
58 81
57 81
56 81
55 81
54 81
53 81
52 81
51 81
50 81
49 81
48 81
47 81
46 81
45 81
44 81
43 81
42 81
41 81
40 81
39 81
38 81
37 81
36 81
35 81
34 81
33 81
32 81
31 81
30 81
29 81
28 81
27 81
26 81
25 81
24 81
23 81
22 81
21 81
20 81
19 81
18 81
17 81
16 81
15 81
14 81
13 81
12 81
11 81
10 81
9 81
8 81
7 81
6 81
5 81
4 81
3 81
2 81
79 80
78 80
77 80
76 80
75 80
74 80
73 80
72 80
71 80
70 80
69 80
68 80
67 80
66 80
65 80
64 80
63 80
62 80
61 80
60 80
59 80
58 80
57 80
56 80
55 80
54 80
53 80
52 80
51 80
50 80
49 80
48 80
47 80
46 80
45 80
44 80
43 80
42 80
41 80
40 80
39 80
38 80
37 80
36 80
35 80
34 80
33 80
32 80
31 80
30 80
29 80
28 80
27 80
26 80
25 80
24 80
23 80
22 80
21 80
20 80
19 80
18 80
17 80
16 80
15 80
14 80
13 80
12 80
11 80
10 80
9 80
8 80
7 80
6 80
5 80
4 80
3 80
2 80
78 79
77 79
76 79
75 79
74 79
73 79
72 79
71 79
70 79
69 79
68 79
67 79
66 79
65 79
64 79
63 79
62 79
61 79
60 79
59 79
58 79
57 79
56 79
55 79
54 79
53 79
52 79
51 79
50 79
49 79
48 79
47 79
46 79
45 79
44 79
43 79
42 79
41 79
40 79
39 79
38 79
37 79
36 79
35 79
34 79
33 79
32 79
31 79
30 79
29 79
28 79
27 79
26 79
25 79
24 79
23 79
22 79
21 79
20 79
19 79
18 79
17 79
16 79
15 79
14 79
13 79
12 79
11 79
10 79
9 79
8 79
7 79
6 79
5 79
4 79
3 79
2 79
68 69
67 69
66 69
65 69
64 69
63 69
62 69
61 69
60 69
59 69
58 69
57 69
56 69
55 69
54 69
53 69
52 69
51 69
50 69
49 69
48 69
47 69
46 69
45 69
44 69
43 69
42 69
41 69
40 69
39 69
38 69
37 69
36 69
35 69
34 69
33 69
32 69
31 69
30 69
29 69
28 69
27 69
26 69
25 69
24 69
23 69
22 69
21 69
20 69
19 69
18 69
17 69
16 69
15 69
14 69
13 69
12 69
11 69
10 69
9 69
8 69
7 69
6 69
5 69
4 69
3 69
2 69
69 70
68 70
67 70
66 70
65 70
64 70
63 70
62 70
61 70
60 70
59 70
58 70
57 70
56 70
55 70
54 70
53 70
52 70
51 70
50 70
49 70
48 70
47 70
46 70
45 70
44 70
43 70
42 70
41 70
40 70
39 70
38 70
37 70
36 70
35 70
34 70
33 70
32 70
31 70
30 70
29 70
28 70
27 70
26 70
25 70
24 70
23 70
22 70
21 70
20 70
19 70
18 70
17 70
16 70
15 70
14 70
13 70
12 70
11 70
10 70
9 70
8 70
7 70
6 70
5 70
4 70
3 70
2 70
70 71
69 71
68 71
67 71
66 71
65 71
64 71
63 71
62 71
61 71
60 71
59 71
58 71
57 71
56 71
55 71
54 71
53 71
52 71
51 71
50 71
49 71
48 71
47 71
46 71
45 71
44 71
43 71
42 71
41 71
40 71
39 71
38 71
37 71
36 71
35 71
34 71
33 71
32 71
31 71
30 71
29 71
28 71
27 71
26 71
25 71
24 71
23 71
22 71
21 71
20 71
19 71
18 71
17 71
16 71
15 71
14 71
13 71
12 71
11 71
10 71
9 71
8 71
7 71
6 71
5 71
4 71
3 71
2 71
67 68
66 68
65 68
64 68
63 68
62 68
61 68
60 68
59 68
58 68
57 68
56 68
55 68
54 68
53 68
52 68
51 68
50 68
49 68
48 68
47 68
46 68
45 68
44 68
43 68
42 68
41 68
40 68
39 68
38 68
37 68
36 68
35 68
34 68
33 68
32 68
31 68
30 68
29 68
28 68
27 68
26 68
25 68
24 68
23 68
22 68
21 68
20 68
19 68
18 68
17 68
16 68
15 68
14 68
13 68
12 68
11 68
10 68
9 68
8 68
7 68
6 68
5 68
4 68
3 68
2 68
66 67
65 67
64 67
63 67
62 67
61 67
60 67
59 67
58 67
57 67
56 67
55 67
54 67
53 67
52 67
51 67
50 67
49 67
48 67
47 67
46 67
45 67
44 67
43 67
42 67
41 67
40 67
39 67
38 67
37 67
36 67
35 67
34 67
33 67
32 67
31 67
30 67
29 67
28 67
27 67
26 67
25 67
24 67
23 67
22 67
21 67
20 67
19 67
18 67
17 67
16 67
15 67
14 67
13 67
12 67
11 67
10 67
9 67
8 67
7 67
6 67
5 67
4 67
3 67
2 67
68 69
67 69
66 69
65 69
64 69
63 69
62 69
61 69
60 69
59 69
58 69
57 69
56 69
55 69
54 69
53 69
52 69
51 69
50 69
49 69
48 69
47 69
46 69
45 69
44 69
43 69
42 69
41 69
40 69
39 69
38 69
37 69
36 69
35 69
34 69
33 69
32 69
31 69
30 69
29 69
28 69
27 69
26 69
25 69
24 69
23 69
22 69
21 69
20 69
19 69
18 69
17 69
16 69
15 69
14 69
13 69
12 69
11 69
10 69
9 69
8 69
7 69
6 69
5 69
4 69
3 69
2 69
69 70
68 70
67 70
66 70
65 70
64 70
63 70
62 70
61 70
60 70
59 70
58 70
57 70
56 70
55 70
54 70
53 70
52 70
51 70
50 70
49 70
48 70
47 70
46 70
45 70
44 70
43 70
42 70
41 70
40 70
39 70
38 70
37 70
36 70
35 70
34 70
33 70
32 70
31 70
30 70
29 70
28 70
27 70
26 70
25 70
24 70
23 70
22 70
21 70
20 70
19 70
18 70
17 70
16 70
15 70
14 70
13 70
12 70
11 70
10 70
9 70
8 70
7 70
6 70
5 70
4 70
3 70
2 70
70 71
69 71
68 71
67 71
66 71
65 71
64 71
63 71
62 71
61 71
60 71
59 71
58 71
57 71
56 71
55 71
54 71
53 71
52 71
51 71
50 71
49 71
48 71
47 71
46 71
45 71
44 71
43 71
42 71
41 71
40 71
39 71
38 71
37 71
36 71
35 71
34 71
33 71
32 71
31 71
30 71
29 71
28 71
27 71
26 71
25 71
24 71
23 71
22 71
21 71
20 71
19 71
18 71
17 71
16 71
15 71
14 71
13 71
12 71
11 71
10 71
9 71
8 71
7 71
6 71
5 71
4 71
3 71
2 71
67 68
66 68
65 68
64 68
63 68
62 68
61 68
60 68
59 68
58 68
57 68
56 68
55 68
54 68
53 68
52 68
51 68
50 68
49 68
48 68
47 68
46 68
45 68
44 68
43 68
42 68
41 68
40 68
39 68
38 68
37 68
36 68
35 68
34 68
33 68
32 68
31 68
30 68
29 68
28 68
27 68
26 68
25 68
24 68
23 68
22 68
21 68
20 68
19 68
18 68
17 68
16 68
15 68
14 68
13 68
12 68
11 68
10 68
9 68
8 68
7 68
6 68
5 68
4 68
3 68
2 68
66 67
65 67
64 67
63 67
62 67
61 67
60 67
59 67
58 67
57 67
56 67
55 67
54 67
53 67
52 67
51 67
50 67
49 67
48 67
47 67
46 67
45 67
44 67
43 67
42 67
41 67
40 67
39 67
38 67
37 67
36 67
35 67
34 67
33 67
32 67
31 67
30 67
29 67
28 67
27 67
26 67
25 67
24 67
23 67
22 67
21 67
20 67
19 67
18 67
17 67
16 67
15 67
14 67
13 67
12 67
11 67
10 67
9 67
8 67
7 67
6 67
5 67
4 67
3 67
2 67
77 78
76 78
75 78
74 78
73 78
72 78
71 78
70 78
69 78
68 78
67 78
66 78
65 78
64 78
63 78
62 78
61 78
60 78
59 78
58 78
57 78
56 78
55 78
54 78
53 78
52 78
51 78
50 78
49 78
48 78
47 78
46 78
45 78
44 78
43 78
42 78
41 78
40 78
39 78
38 78
37 78
36 78
35 78
34 78
33 78
32 78
31 78
30 78
29 78
28 78
27 78
26 78
25 78
24 78
23 78
22 78
21 78
20 78
19 78
18 78
17 78
16 78
15 78
14 78
13 78
12 78
11 78
10 78
9 78
8 78
7 78
6 78
5 78
4 78
3 78
2 78
78 79
77 79
76 79
75 79
74 79
73 79
72 79
71 79
70 79
69 79
68 79
67 79
66 79
65 79
64 79
63 79
62 79
61 79
60 79
59 79
58 79
57 79
56 79
55 79
54 79
53 79
52 79
51 79
50 79
49 79
48 79
47 79
46 79
45 79
44 79
43 79
42 79
41 79
40 79
39 79
38 79
37 79
36 79
35 79
34 79
33 79
32 79
31 79
30 79
29 79
28 79
27 79
26 79
25 79
24 79
23 79
22 79
21 79
20 79
19 79
18 79
17 79
16 79
15 79
14 79
13 79
12 79
11 79
10 79
9 79
8 79
7 79
6 79
5 79
4 79
3 79
2 79
76 77
75 77
74 77
73 77
72 77
71 77
70 77
69 77
68 77
67 77
66 77
65 77
64 77
63 77
62 77
61 77
60 77
59 77
58 77
57 77
56 77
55 77
54 77
53 77
52 77
51 77
50 77
49 77
48 77
47 77
46 77
45 77
44 77
43 77
42 77
41 77
40 77
39 77
38 77
37 77
36 77
35 77
34 77
33 77
32 77
31 77
30 77
29 77
28 77
27 77
26 77
25 77
24 77
23 77
22 77
21 77
20 77
19 77
18 77
17 77
16 77
15 77
14 77
13 77
12 77
11 77
10 77
9 77
8 77
7 77
6 77
5 77
4 77
3 77
2 77
75 76
74 76
73 76
72 76
71 76
70 76
69 76
68 76
67 76
66 76
65 76
64 76
63 76
62 76
61 76
60 76
59 76
58 76
57 76
56 76
55 76
54 76
53 76
52 76
51 76
50 76
49 76
48 76
47 76
46 76
45 76
44 76
43 76
42 76
41 76
40 76
39 76
38 76
37 76
36 76
35 76
34 76
33 76
32 76
31 76
30 76
29 76
28 76
27 76
26 76
25 76
24 76
23 76
22 76
21 76
20 76
19 76
18 76
17 76
16 76
15 76
14 76
13 76
12 76
11 76
10 76
9 76
8 76
7 76
6 76
5 76
4 76
3 76
2 76
74 75
73 75
72 75
71 75
70 75
69 75
68 75
67 75
66 75
65 75
64 75
63 75
62 75
61 75
60 75
59 75
58 75
57 75
56 75
55 75
54 75
53 75
52 75
51 75
50 75
49 75
48 75
47 75
46 75
45 75
44 75
43 75
42 75
41 75
40 75
39 75
38 75
37 75
36 75
35 75
34 75
33 75
32 75
31 75
30 75
29 75
28 75
27 75
26 75
25 75
24 75
23 75
22 75
21 75
20 75
19 75
18 75
17 75
16 75
15 75
14 75
13 75
12 75
11 75
10 75
9 75
8 75
7 75
6 75
5 75
4 75
3 75
2 75
73 74
72 74
71 74
70 74
69 74
68 74
67 74
66 74
65 74
64 74
63 74
62 74
61 74
60 74
59 74
58 74
57 74
56 74
55 74
54 74
53 74
52 74
51 74
50 74
49 74
48 74
47 74
46 74
45 74
44 74
43 74
42 74
41 74
40 74
39 74
38 74
37 74
36 74
35 74
34 74
33 74
32 74
31 74
30 74
29 74
28 74
27 74
26 74
25 74
24 74
23 74
22 74
21 74
20 74
19 74
18 74
17 74
16 74
15 74
14 74
13 74
12 74
11 74
10 74
9 74
8 74
7 74
6 74
5 74
4 74
3 74
2 74
72 73
71 73
70 73
69 73
68 73
67 73
66 73
65 73
64 73
63 73
62 73
61 73
60 73
59 73
58 73
57 73
56 73
55 73
54 73
53 73
52 73
51 73
50 73
49 73
48 73
47 73
46 73
45 73
44 73
43 73
42 73
41 73
40 73
39 73
38 73
37 73
36 73
35 73
34 73
33 73
32 73
31 73
30 73
29 73
28 73
27 73
26 73
25 73
24 73
23 73
22 73
21 73
20 73
19 73
18 73
17 73
16 73
15 73
14 73
13 73
12 73
11 73
10 73
9 73
8 73
7 73
6 73
5 73
4 73
3 73
2 73
CGSCCO
Note: Every pair of numbers are in new line in actual output.
I have written a code to print a snake and ladder grid.
I want the numbers to be aligned such that they are in a straight vertical line.
My code is:
for i in range(100,0,-1):
if i%20 == 0:
for i in range(i,i-10,-1):
print(i, end = " ")
print()
elif i%10 == 0:
for i in range(i-9,i+1):
print(i, end = " ")
print()
The present output is:
100 99 98 97 96 95 94 93 92 91
81 82 83 84 85 86 87 88 89 90
80 79 78 77 76 75 74 73 72 71
61 62 63 64 65 66 67 68 69 70
60 59 58 57 56 55 54 53 52 51
41 42 43 44 45 46 47 48 49 50
40 39 38 37 36 35 34 33 32 31
21 22 23 24 25 26 27 28 29 30
20 19 18 17 16 15 14 13 12 11
1 2 3 4 5 6 7 8 9 10
If you're using Python3, try replacing your:
print(i, end = " ")
lines with:
print(format(i, '6d'), end='')
If you must have the numbers left-justified, try this instead:
print('{:<6d}'.format(i), end='')
These will account for the fact that not every number has the same amount of digits, yet you want every number to take up the same amount of space.