lalitmee
8/24/2018 - 7:46 PM

Python best Practices and clever Solutions

Python best Practices and clever Solutions

''' For example,
filter_list([1,2,'aasf','1','123',123]) == [1,2,123]
'''
def filter_list(l):
  'return a new list with the strings filtered out'
  return [i for i in l if not isinstance(i, str)]
''' For example,
take 153 (3 digits):
1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153
'''
def narcissistic(value):
    return value == sum(int(x) ** len(str(value)) for x in str(value))