## Python Coding Tips: Set & List

The following code snippets are very helpful during sets and list operations. Intersection of sets must check for valid case \$ cat sets.py s1 = {1,2,3} s2 = {} # empty sets means the intersection is empty too! s3 = {} if set(s1) & set(s2): print(s1.intersection(s2)) else: print("no intersection") Result \$ python sets.py no intersection…

## Another Solution: Longest Palindrome Substring

class Solution(object): def __init__(self): self.lookup = {"test"} def isPalindrome(self, s, i, k): j = i + k - 1 if s[i] == s[j]: key = self.createKey(i + 1, j - 1) if key in self.lookup: #self.lookup.remove(key) return True return False def createKey(self, i, j): #return "{}:{}".format(i,j) #return (i, j) #key = bin(i) + bin(j) #return…

## 2+6+10+14+18+22+26+30+34+38=200, choose any five numbers to get sum of 100

2+6+10+14+18+22+26+30+34+38=200 2(1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 + 19)  = 200 Let's simplify it and get ten odd numbers that sum to 100. 2(1 + 3 + 5 + 7 + 9 + 11 + 13 + 15 + 17 + 19)  = 200…