This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89] | |
b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13] | |
a = list(set(a)) | |
b = list(set(b)) | |
def common_element(): | |
return [x for x in a for y in b if x == y] | |
print common_element() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_of_three(a,b,c): | |
if a > b: | |
if a > c: | |
return "The largest of 3 nos is : {}".format(a) | |
else: | |
return "The largest of 3 nos is : {}".format(c) | |
else: | |
if b > c: | |
return "The largest of 3 nos is : {}".format(b) | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def if_powerof(n,x): | |
var = n | |
power = 0 | |
if n%x == 0: | |
while var > 1: | |
if var % x == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import combinations | |
nums2 = [-25,-10,-7,-3,2,4,8,10] | |
def sum_of_3_0(list1, sum1): | |
print "List of possible combinations : {}".format([list(comb) for comb in combinations(list1, 3) if sum(comb) == sum1]) | |
sum_of_3_0(nums2, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def alphabet_position(text_string): | |
dict1 = {value: (int(key) + 1) for key, value in enumerate(list(string.ascii_lowercase))} | |
return " ".join([str(dict1[alp]) for alp in list(text_string.lower()) if alp.isalpha()]) | |
print alphabet_position("The sunset sets at twelve o' clock.") | |
Output : | |
"20 8 5 19 21 14 19 5 20 19 5 20 19 1 20 20 23 5 12 22 5 15 3 12 15 3 11" |