def is_palindrome(word):
reversed_string = "".join(reversed(str(word)))
return True if word.lower() == reversed_string.lower() else False
print is_palindrome(raw_input("Enter word to check : "))
import string
alphapets_list = list(string.ascii_lowercase)
def word_Encoder(input_string,decode_shift_value):
decoded_words = []
for letters in list(input_string):
letter_index = alphapets_list.index(str(letters).lower())
if (letter_index + decode_shift_value) > 25:
letter_index = decode_shift_value - int(25 - letter_index)
else: letter_index = letter_index + decode_shift_value
if str(letters).islower():
decoded_words.append(alphapets_list[letter_index])
elif str(letters).isupper():
decoded_words.append(str(alphapets_list[letter_index]).upper())
alien_language = "".join(decoded_words)
return alien_language
def word_Decoder(input_string,decode_shift_value):
decoded_words = []
for letters in list(input_string):
letter_index = alphapets_list.index(str(letters).lower())
if (letter_index + decode_shift_value) < 1:
letter_index = decode_shift_value - int(25 - letter_index)
else: letter_index = letter_index - decode_shift_value
if str(letters).islower():
decoded_words.append(alphapets_list[letter_index])
elif str(letters).isupper():
decoded_words.append(str(alphapets_list[letter_index]).upper())
Normal_language = "".join(decoded_words)
return Normal_language
input_string = 'Java'
decode_shift_value = 4
encoded_message = [word_Encoder(words,decode_shift_value) for words in input_string.split()]
encoded_message = " ".join(encoded_message)
print "Encoded_message : ",encoded_message
decoded_message = [word_Decoder(words,decode_shift_value) for words in encoded_message.split()]
decoded_message = " ".join(decoded_message)
print "Decoded_message : ",decoded_message
#Output
#input_string = 'Java'
#decode_shift_value = 4
# Encoded_message : Neze
# Decoded_message : Java
def WordPartitions(No_of_Digits,String_Value,threshold,Split_Count):
if (len(String_Value) % Split_Count) == 0 and No_of_Digits == len(String_Value):
partition_size = len(String_Value) / Split_Count
temp_list = []
valid_partitions = []
for chars in list(String_Value):
temp_list.append(str(chars))
if len(temp_list) == partition_size:
partition_value = int(''.join(temp_list))
if partition_value < threshold:
valid_partitions.append(partition_value)
temp_list = []
return sum(valid_partitions)
No_of_Digits = 10
String_Value = "1234567891"
threshold = 99
Split_Count = 5
print "Sum of Partitions : ",WordPartitions(No_of_Digits,String_Value,threshold,Split_Count)
#Output
#Sum of Partitions : 271
Fn = lambda x : [val * val for val in x]
K, M = map(int,raw_input().split())
if 1<= K <=7 and 1 <= M <= 1000:
total_inputs = []
for _ in range(0,K):
total_inputs.append(map(int,str(raw_input()).split()))
req =[max(val) for val in total_inputs if 1 <= len(val) <=7 and max(val)<=1000000000 and min(val) > 0]
ans = int(sum(Fn(req))) % M
print ans
#Input
# 3 1000
# 2 5 4
# 3 7 8 9
# 5 5 7 8 9 10
#output
# 206
def validate_postel_code(input_value):
def integer_in_range(input_value):
return True if 100000 <= int(input_value) <= 999999 else False
def alternating_repetitive_digit_pair(input_value):
alternative_digits = []
input_list = list(input_value)
length = len(input_list)
for id in xrange(0, len(input_list) - 1):
new_index = input_list[id + 2] if length > id + 2 else 0
if input_list[id] == new_index:
alternative_digits.append(input_list[id])
return alternative_digits
if integer_in_range(input_value) and len(alternating_repetitive_digit_pair(input_value)) >=2 : return True
else: return False
print validate_postel_code('121426') # Here, 1 is an alternating repetitive digit.
print validate_postel_code('523563') # Here, NO digit is an alternating repetitive digit.
print validate_postel_code('552523') # Here, both 2 and 5 are alternating repetitive digits.
#Output
# False
# False
# True
def is_power_of(N,P):
if N > 0:
if int(N % P) == 0: return True
else: is_power_of(P,N/P)
# N is an positive integer
# P is a power value
print is_power_of(9,3)
#True
Given 2 ints, a and b, return their sum. However, sums in the range 10..19 inclusive, are forbidden, so in that case just return 20.
Example:
sorta_sum(3, 4) → 7
sorta_sum(9, 4) → 20
sorta_sum(10, 11) → 21
def sorta_sum(A,B):
sum_value = A + B
if 10 <= sum_value <= 19: return 20
else: return sum_value
print sorta_sum(3,4)
print sorta_sum(9,4)
print sorta_sum(10,11)