Ad
Strings
Data Types
Arrays
Code
Diff
  • def Special_Fission(input):
        return list(filter(lambda letter: letter.isalpha(), input))
    • def Special_Fission(input):
    • return [i for i in input if i.isalpha()]
    • return list(filter(lambda letter: letter.isalpha(), input))
Code
Diff
  • def intertwine(text):
        half = len(text)//2
        return "".join([text[i]+text[half+i] for i in range(half)])
    • from itertools import chain
    • def intertwine(text):
    • half = len(text) // 2
    • return "".join(chain.from_iterable(zip(text[:half], text[half:])))
    • half = len(text)//2
    • return "".join([text[i]+text[half+i] for i in range(half)])
Code
Diff
  • from itertools import chain
    
    def intertwine(text):
        half = len(text) // 2
        return "".join(chain.from_iterable(zip(text[:half], text[half:])))
    • from itertools import chain
    • def intertwine(text):
    • half = len(text) // 2
    • return "".join(["".join(pair) for pair in zip(text[:half], text[half:])])
    • return "".join(chain.from_iterable(zip(text[:half], text[half:])))
Code
Diff
  • def intertwine(text):
        half = len(text) // 2
        return "".join(["".join(pair) for pair in zip(text[:half], text[half:])])
    • def intertwine(text):
    • return ''.join([val+'' for pair in zip(text[:len(text)//2], text[len(text)//2:]) for val in pair])
    • half = len(text) // 2
    • return "".join(["".join(pair) for pair in zip(text[:half], text[half:])])
Code
Diff
  • def add(_, __):
         return _ - -__
    • def add(a, b):
    • return a - -b
    • def add(_, __):
    • return _ - -__
Code
Diff
  • common_substring = lambda a, b: a in b
    • from operator import contains
    • common_substring = lambda a, b: contains(b, a)
    • common_substring = lambda a, b: a in b
Code
Diff
  • from operator import contains as common_substring
    • from operator import contains as common_substring
    • def common_substring(string, sub_str):
    • # Write your code here
    • if sub_str in string:
    • return True
    • else:
    • return False
    • from operator import contains as common_substring
Code
Diff
  • from math import sqrt
    
    def primemaker(x):
        if x < 2:
            return []
        else:
            primes = [2]
            for possible_prime in range(3, (x+1), 2):
                limit = sqrt(possible_prime)
                for prime in primes:
                    if prime > limit:
                        primes.append(possible_prime)
                        break
                    if not possible_prime % prime:
                        break
            return primes
    
    
    • from math import sqrt
    • def primemaker(x):
    • primes = []
    • if x < 2:
    • return []
    • else:
    • primes.append(2)
    • for possible_prime in range(3,(x+1), 2): #only odd numbers
    • else:
    • primes = [2]
    • for possible_prime in range(3, (x+1), 2):
    • limit = sqrt(possible_prime)
    • for prime in primes:
    • if prime > limit:
    • primes.append(possible_prime)
    • break
    • if not possible_prime % prime:
    • break
    • return primes
    • return primes
Code
Diff
  • from math import sqrt
    
    def primemaker(x):
        if x < 2:
            return []
        else:
            primes = [2]
            for possible_prime in range(3, x+1, 2): # check only odd numbers
                limit = sqrt(possible_prime)
                for prime in primes:
                    if prime > limit:
                        primes.append(possible_prime)
                        break
                    if 0 == possible_prime % prime:
                        break
        return primes
    
    
    • from math import sqrt
    • def primemaker(x):
    • primes = []
    • if x < 2:
    • return []
    • else:
    • primes.append(2)
    • for possible_prime in range(3,(x+1), 2): # only odd numbers
    • else:
    • primes = [2]
    • for possible_prime in range(3, x+1, 2): # check only odd numbers
    • limit = sqrt(possible_prime)
    • for prime in primes:
    • if prime > limit:
    • primes.append(possible_prime)
    • break
    • if 0 == possible_prime % prime:
    • break
    • return primes
Code
Diff
  • from math import sqrt
    
    def primemaker(x):
        primes = []
        if x < 2:
            return []
        else:  
            primes.append(2)
            for possible_prime in range(3,(x+1), 2): # only odd numbers
                limit = sqrt(possible_prime)
                for prime in primes:
                    if prime > limit:
                        primes.append(possible_prime)
                        break
                    if 0 == possible_prime % prime:
                        break
        return primes
    
    
    • from math import sqrt
    • def primemaker(x):
    • primes = []
    • if x < 2:
    • return []
    • else:
    • primes.append(2)
    • for possible_prime in range(3,(x+1), 2): # only odd numbers
    • limit = sqrt(possible_prime)
    • is_prime = True
    • for prime in primes:
    • if prime > limit:
    • primes.append(possible_prime)
    • break
    • if 0 == possible_prime % prime:
    • is_prime = False
    • break
    • if is_prime:
    • primes.append(possible_prime)
    • return primes
Code
Diff
  • from math import sqrt
    
    def primemaker(x):
        primes = []
        if x < 2:
            return []
        else:  
            primes.append(2)
            for possible_prime in range(3,(x+1), 2): # only odd numbers
                limit = sqrt(possible_prime)
                is_prime = True
                for prime in primes:
                    if prime > limit:
                        break
                    if 0 == possible_prime % prime:
                        is_prime = False
                        break
                if is_prime:
                    primes.append(possible_prime)
        return primes
    
    
    • from math import sqrt
    • def primemaker(x):
    • primes = []
    • if x < 2 : return []
    • else:
    • primes.append(2)
    • for possibleprimes in range(3,(x+1), 2): # only odd numbers
    • isprime = True
    • for n in range(2,possibleprimes//2+1):
    • if possibleprimes % n == 0:
    • isprime = False
    • break # stop after first non prime number found
    • if isprime:
    • primes.append(possibleprimes)
    • primes = []
    • if x < 2:
    • return []
    • else:
    • primes.append(2)
    • for possible_prime in range(3,(x+1), 2): # only odd numbers
    • limit = sqrt(possible_prime)
    • is_prime = True
    • for prime in primes:
    • if prime > limit:
    • break
    • if 0 == possible_prime % prime:
    • is_prime = False
    • break
    • if is_prime:
    • primes.append(possible_prime)
    • return primes
Code
Diff
  • def FindOnly(values):
        for value in set(values):
            if 1 == values.count(value): # check value is unique
                return value
    • def FindOnly(list):
    • comparable_list = [(str(x), i) for i, x in enumerate(list)]
    • comparable_list.sort()
    • for i in range(-1, len(list)-1):
    • if comparable_list[i][0] != comparable_list[i-1][0] and comparable_list[i][0] != comparable_list[i+1][0]:
    • return list[comparable_list[i][1]]
    • def FindOnly(values):
    • for value in set(values):
    • if 1 == values.count(value): # check value is unique
    • return value