/
is_palendrome.txt
2053 lines (1655 loc) · 72.2 KB
/
is_palendrome.txt
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
def is_palendrome(s):
"""Check whether a string is a palindrome"""
# palindrome = 'abc'
# if len(s)!= len(s[::-1]):
# return False
result = s[0]
for i in range(1, len(s) - 1, -1):
# result = s[i-1]
result += s[i]
# result = s[i-1] + s[i]
result += s[i]
return result == s[::-1]
def is_palindrome_reverse(s):
"""Check whether a string is a palindrome in reverse"""
# palindrome_reverse = s[::-1]
# if len(s)!= len(s[::-1]):
# return False
result = s[0]
for i in range(1, len(s) - 1, -1):
# result = s[i-1]
result += s[i]
# result = s[i-1] + s[i]
result += s[i]
return result == s
def main():
"""Your code goes here. Write your program in Python in here."""
input_string = "stackoverflow"
if is_palindrome(input_string):
print("Palindrome: {}".format(input_string))
if is_palindrome_reverse(input_string):
print("Palindrome in reverse: {}".format(input_string))
else:
print("NOT A PALINDROME")
input_string = "stackoverflow"
if is_palindrome_reverse(input_string):
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
# Make sure string is not empty
if s == "":
return False
# Grab length of string
length = len(s)
# Find last character in the string
lastChar = s[length - 1]
# Find first character in the string
firstChar = s[0]
# If last character is same as the first character, string is palindrome
return lastChar == firstChar
def is_prime(num):
"""Check whether a number is prime"""
# Make sure number is not negative
if num < 1:
return False
# If number is even
if num % 2 == 0:
return False
# Recursively check each factor from 2 to sqrt(num)
for div in range(3, int(math.sqrt(num)) + 1, 2):
if num % div == 0:
return False
return True
def list2d(l):
"""Build a list containing a row of lists, as output"""
# Get rows
rows = [l]
for i in range(len(l)):
rows.append([])
# Loop through every element in the list
for i in range(len(l)):
# Append new row to output
rows[i].append(l[i])
return rows
<|endoftext|>Q:
Why don't I have a "little" helper component?
So... I have my composer.json file generated with php composer.phar create-project library/xxx project-name and now I have a folder in my project containing... You guessed it... all my library files in there.
Now, I went to add my own folder of files like:
composer.json
helpers.php
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
if s[::-1] == s:
return True
else:
return False
def solve(m):
"""Find the length of a factorization, and return it."""
m = nump(m)
assert m > 2
# sanity checks
if not is_palindrome(m):
print("""This will not work. The product of a palindrome and a non-palindrome cannot be a palindrome."""\
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
return (s[::-1] == s)
def encode_integer_to_digits(n, i=1):
"""Encode a number to the base i"""
digits = ''
while n:
digits = str(n % i) + digits
n //= i
return digits
def is_isomorphic(a, b):
"""Determine if two strings are isomorphic"""
if len(a)!= len(b):
return False
i = 0
for j in xrange(len(a)):
if b[j]!= a[i]:
return False
return True
def is_palindrome(s):
"""Check whether a string is a palindrome"""
if len(s)!= len(s[::-1]):
return False
for j in xrange(len(s)):
if s[j]!= s[::-j]:
return False
return True
def is_prime(num):
"""Find whether a number is prime or not"""
if num < 2:
return False
if num % 2 == 0:
return True
for divisor in range(3, num + 1, 2):
if num % divisor == 0:
return False
return True
def is_posnum(str):
"""Is the given string a valid number?"""
n = int(str)
return n == str(n) and n.is_integer()
def is_base2(str):
"""Check whether the
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
if s == s[::-1]:
return True
else:
return False
def main():
"""Main function"""
if len(sys.argv)!= 2:
print('Usage: python %s <filename>' % sys.argv[0])
sys.exit(1)
with open(sys.argv[1], 'r') as f:
new_palindromes = []
# Read the file
for line in f:
# Get the word from each line
word = line.strip()
# Find the length of word and it's lexicographic ordering
word_length = len(word)
ordering = [int(j) for j in word[::-1]]
# Sort the dictionary with their lexicographic ordering
for j, k in enumerate(ordering):
dictionary[j].append(k)
# Find out if the word is a palindrome
if is_palindrome(word):
new_palindromes.append(word)
# Store the new palindrome list in a file
with open('new_palindrome.txt', 'w') as f:
for i in new_palindromes:
f.write(i + '\n')
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
s = s.replace(' ', '')
s = s.lower()
return s == s[::-1]
def part_of_palindrome(s):
"""Check whether a string contains the last part of a palindrome"""
return s[-1] == s[-2] + s[-3] + s[-4] + s[-5]
if __name__ == '__main__':
main()
<|endoftext|>Normal development of the gastrointestinal tract is required for initiation of the gut immune system, tolerance to microorganisms, and proper nutrition and nutrient absorption. We have demonstrated that an adult small intestinal protein lysosomal hydrolase, cathepsin-L, has potent suppressive activity toward the proliferation of immature T lymphocytes. The mechanism(s) of this suppression appear to involve an intrinsic ability of cathepsin-L to block the IL-2R pathway in T cells, thus inhibiting IL-2-dependent lymphokine production and mitogenesis. Consistent with a role for the cathepsin-L in immune suppression, the IL-2-induced down-regulation of the cathepsin-L promoter in T cells is the same defect found in T cells from intestinal inflammation or from a lupus mouse model. The expression of the cathepsin-L promoter can also be induced in vivo in mice undergoing ovalbumin-induced enteritis. Studies with monoclonal anti- T cell antibodies indicate that suppressor and non-suppressor T cells are the targets of suppressor cathepsin-L. In addition, we have demonstrated that IL-2-mediated T cell proliferation is impaired in patients with active inflammatory bowel disease (IBD) and multiple sclerosis (MS), indicating a role for this regulation in immune mediated disorders. Given that the intestine is the site where the most prominent forms of human IBD occur, and that oral probiotic therapy is a possible treatment for IBD, we propose to further examine the therapeutic potential of oral probiotic treatment for MS. This is a phase II/III clinical trial which consists of randomizing patients with relapsing-remitting MS to receive orally administered strains of Lactobacillus rhamnosus (JB-1 or GG) or a placebo for a 12-week period. Primary outcome is the change
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
if len(s)%2:
return False
return s == s[::-1]
The code of that function is clean and pretty readable, but what about that palindrome check on its own?
def is_palendrome(s):
"""Check whether a string is a palindrome"""
if len(s)%2:
return False
return s == s[::-1]
I wouldn't change anything in the function body, but as long as I need to use that function it would be nice to have it print something to remind me that I should rewrite it.
One way to solve this is to enclose it inside a function that, if and when it is executed, prints something like what's shown in the first example.
def is_palendrome_with_pdb(s):
"""Check whether a string is a palindrome"""
if len(s)%2:
pdb.set_trace() # here it starts
return False
return s == s[::-1]
But again, I don't like this. I like the solution presented in the previous paragraph, as it avoids typing the "this is not a palindrome" message into the code.
One more thing. I love variable names that show their role (is_palindrome), and are consistent with the right side of the equality sign (=) (such as is_palindrome).
The actual string to be checked is called s. I don't like that. I like the s in is_palindrome. I also like to have such names on the left side of the assignment expression (:) as in print(s) or return s;.
There are ways to keep the s in the name and still make the code better, but to keep it simple I decided to go for a name that is the concatenation of the words palindrome and check.
So, what do you think? Is this a nice way of solving the problem, or have I missed some obvious mistake? Is there a better way to write the code? Is there a better title for this post?
A:
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
l = len(s)
if l % 2!= 0:
return False
if l < 3:
return True
if s[l-1]!= s[-l-1]:
return False
for i in range(1, l/2):
if s[i]!= s[l-i]:
return False
return True
s = input("Enter a string: ")
print(is_palendrome(s))
<|endoftext|>[Application of computer based automated X-ray analysis in assessment of immunologic effectiveness of nasopharyngeal cancer therapy].
There are no exact ways of evaluating immunologic effect in nasopharyngeal cancer therapy. X-ray morphometry is a well established method for quantitative analysis of the bony structures. However, to analyze the structures which are not bony a powerful software is needed. The aim of this study was to compare computer assisted analysis of X-rays with morphometry. We made a statistical evaluation of computer based automated analysis of X-rays of nasopharyngeal cancer in 36 patients. This analysis showed a good conformity between automated and manual measurement in a case of complete cure of the disease. In a case of relapse of the disease, automated measurement overestimated the tumor size. The correlation coefficient between automated and manual measurements was: r(2) = 0.94, p < 0.001, on nasopharynx - r(2) = 0.90, p < 0.001, on oropharynx. These data demonstrated that automated analysis of X-rays could be a useful method in the assessment of immunologic effectiveness of the treatment.<|endoftext|>cnxps.cmd.push(function () { cnxps({ playerId: '36af7c51-0caf-4741-9824-2c941fc6c17b' }).render('4c4d856e0e6f4e3d808bbc1715e132f6'); });
Several people who had to be evacuated from the scene of an attack on the Israeli embassy in London last week have been questioned by British police about a bomb attack in the
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
n = len(s)
rev = ""
if n % 2:
rev += s[n // 2]
rev = rev[::-1]
if rev == s:
return True
return False
def is_palindrome(s):
"""Check whether a string is a palindrome"""
return s == rev(s)
def is_flip(s):
"""Check whether a string is a palindrome"""
return (s[::-1] == s) and (s[0]!= s[-1])
def is_reverse(s):
"""Check whether a string is a palindrome"""
return (s[::-1] == s) and (s[0] == s[-1])
def is_exact_reverse(s):
"""Check whether a string is an exact reverse of itself"""
return is_flip(s) and is_palindrome(s)
def cmp_iter(a, b):
"""Compare two strings, starting at the end of the string"""
for i in range(len(a)):
if a[i]!= b[i]:
return a[i] > b[i]
return False
def levenshtein(a, b):
"""Levenshtein distance between two strings"""
if len(a) > len(b):
n = len(a)
else:
n = len(b)
prev = None
for i in range(n):
if prev == None:
if a[i] == b[i]:
pass
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
if s == s[::-1]:
return True
return False
def reverse_string(string):
"""Return the reverse of a string, given a string"""
string_rev = ""
for char in string:
if char!= " ":
string_rev = string_rev + char
else:
return string_rev
return string_rev
print(reverse_string(" This is a test"))
A:
Firstly, your if statement should be reversed, because it is already checking if the string is a palindrome, so we are returning palindrome = True or False, instead of the opposite.
Secondly, in reverse_string you return before you even do anything, if it is a palindrome. So it only returns if it is not a palindrome, and never actually attempts to reverse the string. So you can either remove the return statement entirely, or add another condition to check if the length of the returned string is the same as the original string, and only return if both are the same.
Here's what I would suggest:
def reverse_string(string):
if string.ispalindrome():
return reverse_string(string[::-1])
else:
# it is not a palindrome, so reverse it
return "".join(map(str, string[::-1]))
Then test it like so:
print(reverse_string(" This is a test"))
If you want to include the space in the string, you can change this:
if char!= " ":
To this:
if char!= " " and char!= " ":
And this:
if char!= " ":
To this:
if char!= " " and char!= " ":
<|endoftext|>20
Über 130 Millionen US-Amerikaner leben krebsmedizinisch geplagte Städte. Wir sind
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
count = 0
c, s = [], s[0:-1]
while s:
if s == s[-1]:
c += 1
s, s[-1] = s[-1], s[-1] + 1
s[-1] += 1
return len(s) == 0 or c == len(s)
if __name__ == "__main__":
import doctest
doctest.testmod()
A:
Your code is missing return in is_palindrome() and your test failed.
<|endoftext|>Enantioselective oxidation of sulfides catalyzed by chiral phthalate/phosphite and halogenated benzoates in water.
Chiral primary amine/inorganic salts [chiral tertiary amine (R)-3,5-dimethylisoxazole, phosphorous acid/tris(hydroxymethyl)aminomethane borate (R)-dibenzo-18-crown-6] and N-(3,5-dinitrophenyl)propanediamine-conjugated chiral phosphites/phthalates bearing secondary chiral oxazoline groups were screened for the enantioselective oxidation of sulfides in water with haloacetic acids as the oxidants. The oxazoline groups of the catalysts controlled the enantioselectivity of the process. In the presence of a large excess of haloacetic acid (10 equiv of haloacetic acid) and chiral complex, the (R)-configured sulfide was preferentially oxidized to the (S)-enantiomer with >99% ee. However, the use of an excess of sulfide leads to >99% ee.<|endoftext|>Q:
Empty string on Devise registration
I have a strange issue on my Devise registration form. I have no custom form, i'm only passing params[:user].
I created the Rails, Devise and CanCan gems using the Devise tutorial, but this error happens since the initial installation of Devise.
This is my user model:
class User
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
total = s.count(s) + 1
for k in range(total, 0, -1):
if s[k]!= s[total - k - 1]:
return False
return True
def escape_special_chars(string):
"""Escape special chars in string to avoid raising exceptions
during escaping
Examples
--------
>>> escape_special_chars('$user$password$salt$start')
'$user$password$salt$start'
>>> escape_special_chars('$user$password$salt$start?sql_query')
'$user$password$salt$start?sql_query'
"""
escaped = re.sub(
'(%s)', r'\g<0>' % '|'.join(escape_char.strip(escape_char) for escape_char in escape_chars),
string,
)
return ''.join(unescape_str(e) for e in escaped.split('?'))
def generate_values(int_ids, float_ids, input_chars):
"""generate different values for each int/float"""
# No identity could not be generated for int/float keys
identity = {}
identity[int_ids] = {}
identity[int_ids]['_sharded'] = 1
if input_chars is not None:
# only sharded for the original char
identity[input_chars][int_ids] = 1
identity[int_ids][input_chars] = 1
identity[float_ids] = {}
identity[float_ids]['_sharded'] = 1
if input_chars is not None:
identity[input_
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
# Left palindrome: if s[0] == s[-1]
# Right palindrome: if s[-1] == s[0]
# The result is true if the string is palindrome.
s[0] = '<palindrome>'
s[1] = '<palindrome>'
return s == '<palindrome>'
A:
Don't forget about the singleton set:
>>> palindrome_singleton = set([s] for s in string)
>>> palindrome_singleton.add("test")
>>> palindrome_singleton
{'test'}
<|endoftext|>BLOG
The talk about AI is not new. The phrase often arises when one does an internet search, or one asks others how they are going to fill that newly vacant job in their company, or any other moment that the AI is being touted by a celebrity or random twit.
The usage has now spread to the workplace too, where it is becoming the default (if not only) word to use to describe the new hot technology. Such is the obsession that we are already seeing that companies are starting to hold all their meetings in AI meetings. Some are even offering discounts to employees if they attend those meetings.
I don't even know what AI is so I won't be too impressed if someone tells me that he attended one today. But I am fascinated to find out what it is. So let's get going and see what this new AI thing actually is. What does it do and how would it help us all?
Let's start by understanding the anatomy of an AI. Think of an AI as a computer program that has been written to react to certain situations in a humanlike way. A good example is the language pattern find and replace where the AI finds and replaces a string or a word or a phrase or a piece of text in a document by another that is typed in by a human user. So while a human can learn to use a keyboard, we have never been taught to do that on a computer.
Therefore, an AI program is like a teacher that acts like a parent to the computer. So while we have developed thousands of computer programs that we have used on our computers (word processing programs, spreadsheet programs, slide show programs, web search programs
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
return "".join(s[::-1]) == s
def is_permutation(A, B):
"""Check whether A can be formed into a permutation of B"""
# http://stackoverflow.com/questions/10189930/check-whether-a-list-can-be-formed-as-a-permutation-of-another-list
if len(A) > len(B):
raise ValueError("List B is longer than A")
elif len(A) == 0:
return True
else:
swapped = []
i = 0
while i < len(A):
if A[i] < B[i]:
swapped.append(B[i])
i += 1
else:
swapped.append(A[i])
i += 1
for k in reversed(swapped):
if k not in B:
return False
return True
def check_formatting(password):
"""Check formatting of an MD5 hashed password"""
# Format validation is handled in check_password function
return check_password(password)
def crypt_password(password):
"""Encrypts the given password"""
return hashlib.md5(password.encode('utf-8')).hexdigest()
def check_password(password):
"""Validates a password and returns a boolean"""
return crypt_password(password) == password
if __
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
if len(s) % 2:
return False
return s == s[::-1]
def main():
# INPUT : a list of characters in string form.
# OUTPUT : True if all characters of the input string are in the output string.
# Else False.
for item in s:
if not item in output:
output.append(item)
return (not is_palendrome(s) or all(s==s[::-1] for s in output))
if __name__ == '__main__':
# get the content of the input file
input_data = open("palindrome_data.txt", 'r').read()
# put input_data into s
s = input_data
# show the output.
print(main())
# print s
print(s)
<|endoftext|>Urinary aquaporin 2 levels correlate with degree of preservation in renal function in crescentic IgA nephropathy.
Immunoglobulin A nephropathy (IgAN) is a common glomerular disease that is known to be characterized by urinary hypoosmolality. Because water channels regulate renal filtration, aquaporins (AQPs) are assumed to be associated with the pathogenesis of IgAN. Although studies have reported AQP levels in kidneys with IgAN, levels in the urine have not been reported. We measured urine AQP2 levels to assess the correlation with urinary water excretion, and estimated glomerular filtration rate (eGFR) in cases of biopsy-proven crescentic IgAN. We also examined the correlations between urine AQP2 levels and the clinical findings of crescentic IgAN. Our results show that urine AQP2 levels are correlated with renal function, which suggests that urinary AQP2 levels are associated with renal function in crescentic IgAN.<|endoftext|>Q:
Reduce dimension of a 2D array using scipy/numpy
I want to find the average of
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
b = s.__bytes__()
if len(b) % 2 == 1:
return False
length = len(b)
pos = 0
for i in range(length):
if b[i]!= b[i + 1]:
return False
pos += 1
return True
<|endoftext|>/*
* Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#include "jni.h"
#include "jni_util.h"
#include "jvm.h"
#include <string.h>
#include "java_lang_String.h"
#include "java_lang_Class.h"
#include "java_lang_StringBuffer.h"
#include "java_lang_reflect_Array.h
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
a, b = s[::-1], s[1::-1]
return a == b
def is_palindrome_sym(s):
"""Check whether a string is a palindrome"""
a, b = s[::-1], s[1::-1]
return a == b
def is_palindrome_sym2(s):
"""Check whether a string is a palindrome"""
a, b = s[::-1], s[1::-1]
return a == b
def s_perm_list(l):
"""Recursive function to list permutations of a list"""
result = []
if len(l) == 1:
result.append(l)
return result
for i in range(len(l)):
for j in range(i + 1, len(l)):
result.append(l[i])
l[i] = l[j]
l[j] = l[i]
l.remove(l[j])
l.remove(l[i])
l.append(l[j])
l.append(l[i])
return result
def palindrome(string):
"""Recursive function to find a palindrome"""
s = string[::-1]
p = s[::-1]
q = s[1::-1]
if is_palendrome(p):
return True
else:
if is_palindrome(q):
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
length = len(s)
return (s[0:length] == s[length::-1])
#write a function that compares whether a number of a certain type is even or odd
def is_even_or_odd(num):
return num % 2 == 0
#write a function that calculates the product of all integers between 0 and a certain number
def prod_numbers_below(n):
result = 1
for i in range(n):
result = result * i
return result
def is_prime(n):
# first, a quick check to see if n is even or odd
if n%2 == 0:
return False
else:
# now check whether n is divisible by any of the numbers from 2 to n-1
for i in range(3, int(n**0.5)+1, 2):
if n % i == 0:
return False
# now check whether n is divisible by the square root of n (the previous one)
for i in range(2, int(n**0.5) + 1, 2):
if n % i == 0:
return False
# check whether n has a prime factor above the square root of n
for i in range(3, int(n**0.5)+1, 2):
if i * i > n:
return False
# if all of the above test failed, it is prime
return True
# write a function that counts the occurrence of a number in a string
def num
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
s = s.upper()
i = 0
j = len(s)-1
while (i <= j):
if s[i] == s[j] and s[i]!='':
if s[i] =='':
i = i + 1
j = j - 1
else:
break
i = i + 1
j = j - 1
if j < len(s) and s[j] =='':
if s[j] == s[i]:
s = s[:j] + s[j + 1:]
return True
return False
def check_palindrome(word, len_word):
"""Checks whether a word is a palindrome of length `len_word`"""
if len_word <= 1:
return False
else:
i = 0
j = len_word - 1
while i <= j:
if check_palindrome(word, i) and check_palindrome(word, j):
return True
i = i + 1
j = j - 1
return False
A:
Your indexing is incorrect.
if (s[i] =='') and (s[j] ==''):
is being run for every space in the string. It should
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
x = 0
start = 1
while start < len(s):
temp = s[x]
x += 1
y = x + 1
while y < len(s):
if s[y]!= temp:
return False
y += 1
start += 1
y = x + 1
while y < len(s):
if s[y]!= temp:
return False
y += 1
return True
def count_palindromes(s):
"""Count the number of palindromes in a string"""
count = 0
if s:
for i in range(len(s)-1):
if is_palendrome(s[i:i+1]):
count += 1
return count
def check_palindrome(s):
"""Checks whether a string is palindrome"""
if is_palendrome(s):
print("That string is palindrome.")
else:
print("That string is not palindrome.")
def reverse_string(s):
"""Reverses a string in-place, returning the result"""
c = 0
s = s[::-1]
while c < len(s):
s[c] = s[c] ^ (s[c+1] + c)
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
return s == s[::-1]
# Sample runs:
>>> palindrome_str = "hello world"
>>> is_palindrome(palindrome_str)
True
>>> palindrome_str = "มนุษย์"
>>> is_palindrome(palindrome_str)
True
I would expect there to be a short and an even shorter version, but I don't know how to go about this.
A:
This is one of those cases where it might be more convenient to use the ord() built-in to compare the strings rather than do an explicit character comparison. That's because ord() is meant to be able to handle strings of any length.
However, this might not give the best performance in all situations, and there's a couple of ways of working out how to do that.
Firstly, you could use str.ljust() to make the string a certain length, e.g.
>>> ''.ljust(13, '-').replace(' ', '-') == '-'-'.ljust(13, '-').replace(' ', '-')
True
If you want to really get to the bottom of it, you can play around with it by inspecting the underlying integers (if you're on Python 3 you can use the. hex() or. int() functions).
Here are a couple of extra ideas:
is_palindrome(chr(s[0]))
For string comparisons, this should perform much better than trying to treat the string as a list or using a regex for instance.
sum(ord(c) for c in s)
If you want the sum of the ordinals, this should be faster than the other methods.
A:
ljust(13, '-').replace(' ', '-') == '-'-ljust(13, '-').replace(' ', '-')
A:
Here's a (possibly) less complicated version that replaces string manipulation operations with the modulus function.
is_palindrome = (('-' * 13) + ''.join([''.join(row) for row in map(chr, range(16, 128, -1))])) == '-'
Your test input is
[''.join(row) for
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
return s == s[::-1]
This is a simple function that returns whether the input is a palindrome.
Now, I want to evaluate this for various numbers such as 2, 3, 9, 27, 81, and 243.
I have many these numbers in a for loop and want to evaluate the function for these numbers. But how to do this is the problem.
How can I evaluate this for these numbers, in a loop?
I have seen the following code, but it does not answer my question.
for x in range(2,100):
if is_palendrome(x):
print(x)
This prints the numbers 2, 3, and so on. But, I need the values 2, 3, 9, 27, 81, and 243.
A:
You are doing it correctly, all you need is to make sure you loop over the whole numbers:
for n in range(2,100):
if is_palendrome(n):
print(n)
Or to do it without a for loop at all:
[n for n in range(2,100) if is_palendrome(n)]
# [2, 3, 9, 27, 81, 243]
However, there is a better solution if you can use list comprehension.
[n for n in range(2,100) if is_palendrome(n)]
# [2, 3, 9, 27, 81, 243]
<|endoftext|>Analysis of refractive error and astigmatism after corneal collagen cross-linking for progressive keratoconus.
To evaluate the visual, refractive, and astigmatic outcomes of corneal collagen cross-linking (CXL) for progressive keratoconus after a mean of 2.5 years. Observational, prospective, cross-sectional case series. We included 26 eyes (26 patients) with progressive keratoconus that were treated with CXL (follow-up, mean ± SD = 23 ± 5 months) at the Bascom Palmer Eye Institute. Visual acuity (Snellen equivalent), manifest refraction, and corneal and retinal astigmatism were measured. Uncorrected visual acuity (logarithm of the minimal angle of resolution)
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
"""Tried: https://www.pycodestyle.org/html/beyond_style/correctness.html#strings"""
start = s[0]
end = s[-1]
result = s
while start < end:
result = result[1]
if start > end:
return result == end[::-1]
start = start[::-1]
end = end[::-1]
return result == s
def is_palindrome(s):
"""Check whether a string is a palindrome, assuming the second half
is reverse of the first."""
if s[-1] == s[0]:
return True
return is_palendrome(s)
if __name__ == '__main__':
import doctest
doctest.testmod()
<|endoftext|>.
[^5]: E.g., *Buy the car, get the car*.
[^6]: Some applications of CNs to entity resolution, as well as the relation-specific sieve models and resolution models (used, e.g., in the recent global test [@jiang2012globally]), are very similar to the ideas introduced in this paper, and hence, they share some problems, such as that a large amount of data is required to construct a reasonable model.
[^7]: We use `@` to highlight the tokens that denote entity mentions in this paper.
[^8]: <http://nlp.stanford.edu/software/lex-parser.shtml>
[^9]: In these experiments, we adopted the following baseline SVM classifier: *Signal Support Vector Machines (SVMs)*, as we also adopted a baseline SVM classifier in the follow-up experiments.
<|endoftext|>December 10, 2016
TOHCC demands prosecution of senior staff over Gaza conflict
The illegal December 7 – 10 unilateral Gaza assault by the Israeli occupation forces (IOF) on the 1
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
n = len(s)
a = list(s)
a.reverse()
return s == list(s)
class Solution(object):
def isPalindrome(self, s):
"""
:type s: str
:rtype: bool
"""
l, r = s[::-1], s[::-1]
if l == r:
return True
else:
return False
<|endoftext|>BASCO, Calif. (AP) — A mountain lion has killed a 2-year-old girl in a rural corner of the San Bernardino National Forest.
The Riverside Press-Enterprise reports the girl was found in the afternoon on Thursday, about 25 miles (40 kilometers) east of Calimesa, the mountain lion’s home.
Forest officials say a kitten was also found and euthanized.
Wildlife officials say the mountain lion was observed in the area Monday.
Wildlife officials say the mountain lion was observed in the area Monday.
Officials say state wildlife officials consider the attack a threatening act, but no other threats have been determined.
Copyright 2018 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.<|endoftext|> *kc*--other thermocline bacteria in shelf--slope. The different names of *Synechococcus* species in the oceans of the Pacific Ocean and the Atlantic Ocean, the usage of single or double names to describe two similar types of *Synechococcus*, and the different classification systems of this type of *Synechococcus* to subdivide it further in the current standard database, make it difficult to compare these results with those in other oceans. More studies on the microorganisms, including populations with different growth rates in the ocean and at different sites, will be needed to elucidate these issues.
This study identified the importance of the *kc*-*dc* gene cluster to chemolithoautotrophy and the export of ammonium
====================
def is_palendrome(s):
"""Check whether a string is a palindrome"""
# input: string s
# returns: boolean
s1 = s[::-1]
return s == s1
def enqueue(word):
"""
Enqueue a word and add its palindrome number to the list if the
palindrome checker returned True
"""
global check_list
check_list.append(str(palindrome_checker(word)))
if palindrome_checker(word):
check_list.append(word)
print("Enqueued:", word)
def dequeue():
"""
Dequeue the maximum palindrome number from the list and print it
"""
global check_list
global top_check
check_list.append(top_check)
top_check = check_list[-1]
top_check_num = int(check_list[-1])
print("Dequeued:", top_check_num)
def queue():
"""
Print the words in the queue
"""
global check_list
for word in check_list:
print(word)
def main():
global queue
"""
Make queue variable, declare list variable and initialize empty list
"""
global check_list
global top_check
queue = deque()
while True:
# enqueue a word and add its palindrome number to the list if the
# palindrome checker returned True
word = input("Enter a word: ")
if is_palendrome(word):
enqueue(word)
====================
def is_palendrome(s):