Input:
CODE <module>()
  RESUME 0
  PUSH_NULL
  LOAD_BUILD_CLASS
  LOAD_CONST <code Pair>
  MAKE_FUNCTION 0
  LOAD_CONST 'Pair'
  LOAD_NAME object
  CALL 3
  STORE_NAME Pair
  LOAD_CONST <code max_chain_length>
  MAKE_FUNCTION 0
  STORE_NAME max_chain_length
  RETURN_CONST None
END
CODE Pair()
  DOC 'Pair'
  RESUME 0
  LOAD_NAME __name__
  STORE_NAME __module__
  LOAD_CONST 'Pair'
  STORE_NAME __qualname__
  LOAD_CONST <code Pair.__init__>
  MAKE_FUNCTION 0
  STORE_NAME __init__
  RETURN_CONST None
END
CODE Pair.__init__(self, a, b)
  RESUME 0
  LOAD_FAST a
  LOAD_FAST self
  STORE_ATTR a
  LOAD_FAST b
  LOAD_FAST self
  STORE_ATTR b
  RETURN_CONST None
END
CODE max_chain_length(arr, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST max
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_CONST 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST mcl
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  CALL 2
  GET_ITER
L5:
  FOR_ITER L10
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST i
  CALL 2
  GET_ITER
L6:
  FOR_ITER L9
  STORE_FAST j
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_ATTR a
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_ATTR b
  COMPARE_OP >
  POP_JUMP_IF_TRUE L7
  JUMP_BACKWARD L6
L7:
  LOAD_FAST mcl
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST mcl
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP <
  POP_JUMP_IF_TRUE L8
  JUMP_BACKWARD L6
L8:
  LOAD_FAST mcl
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST mcl
  LOAD_FAST i
  STORE_SUBSCR
  JUMP_BACKWARD L6
L9:
  END_FOR
  JUMP_BACKWARD L5
L10:
  END_FOR
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
L11:
  FOR_ITER L13
  STORE_FAST i
  LOAD_FAST max
  LOAD_FAST mcl
  LOAD_FAST i
  BINARY_SUBSCR
  COMPARE_OP <
  POP_JUMP_IF_TRUE L12
  JUMP_BACKWARD L11
L12:
  LOAD_FAST mcl
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_FAST max
  JUMP_BACKWARD L11
L13:
  END_FOR
  LOAD_FAST max
  RETURN_VALUE
L14:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L14 depth=2 lasti=False
END

class Pair(object):

    def __init__(self, a, b):
        self.a = a
        self.b = b

def max_chain_length(arr, n):
    max = 0
    mcl = [1 for i in range(n)]
    for i in range(1, n):
        for j in range(0, i):
            if arr[i].a > arr[j].b and mcl[i] < mcl[j] + 1:
                mcl[i] = mcl[j] + 1
    for i in range(n):
        if max < mcl[i]:
            max = mcl[i]
    return max

Prompt: Write a function to find the longest chain which can be formed from the given set of pairs.

assert max_chain_length([Pair(1, 2), Pair(3, 4),Pair(5, 6), Pair(7, 8)], 4) == 4

Creative Commons Attribution 4.0 International

MBPP (Mostly Basic Python Problems), Austin et al. 2021, Google Research


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code first_repeated_char>
  MAKE_FUNCTION 0
  STORE_NAME first_repeated_char
  RETURN_CONST None
END
CODE first_repeated_char(str1)
  RESUME 0
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST str1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST index
  STORE_FAST c
  LOAD_FAST str1
  LOAD_CONST None
  LOAD_FAST index
  LOAD_CONST 1
  BINARY_OP +
  BINARY_SLICE
  LOAD_ATTR NULL|self + count
  LOAD_FAST c
  CALL 1
  LOAD_CONST 1
  COMPARE_OP >
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST c
  SWAP 2
  POP_TOP
  RETURN_VALUE
L3:
  END_FOR
  RETURN_CONST 'None'
END

def first_repeated_char(str1):
    for index, c in enumerate(str1):
        if str1[:index + 1].count(c) > 1:
            return c
    return 'None'

Prompt: Write a python function to find the first repeated character in a given string.

assert first_repeated_char("abcabc") == "a"

assert first_repeated_char("abc") == "None"

assert first_repeated_char("123123") == "1"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_ludic>
  MAKE_FUNCTION 0
  STORE_NAME get_ludic
  RETURN_CONST None
END
CODE get_ludic(n)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST ludics
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST ludics
  LOAD_ATTR NULL|self + append
  LOAD_FAST i
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_CONST 1
  STORE_FAST index
  LOAD_FAST index
  LOAD_GLOBAL NULL + len
  LOAD_FAST ludics
  CALL 1
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L6
L3:
  LOAD_FAST ludics
  LOAD_FAST index
  BINARY_SUBSCR
  STORE_FAST first_ludic
  LOAD_FAST index
  LOAD_FAST first_ludic
  BINARY_OP +
  STORE_FAST remove_index
  LOAD_FAST remove_index
  LOAD_GLOBAL NULL + len
  LOAD_FAST ludics
  CALL 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L5
L4:
  LOAD_FAST ludics
  LOAD_ATTR NULL|self + remove
  LOAD_FAST ludics
  LOAD_FAST remove_index
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  LOAD_FAST remove_index
  LOAD_FAST first_ludic
  BINARY_OP +
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST remove_index
  LOAD_FAST remove_index
  LOAD_GLOBAL NULL + len
  LOAD_FAST ludics
  CALL 1
  COMPARE_OP <
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L4
L5:
  LOAD_FAST index
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST index
  LOAD_FAST index
  LOAD_GLOBAL NULL + len
  LOAD_FAST ludics
  CALL 1
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L6
  JUMP_BACKWARD L3
L6:
  LOAD_FAST ludics
  RETURN_VALUE
END

def get_ludic(n):
    ludics = []
    for i in range(1, n + 1):
        ludics.append(i)
    index = 1
    while index != len(ludics):
        first_ludic = ludics[index]
        remove_index = index + first_ludic
        while remove_index < len(ludics):
            ludics.remove(ludics[remove_index])
            remove_index = remove_index + first_ludic - 1
        index += 1
    return ludics

Prompt: Write a function to get a lucid number smaller than or equal to n.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code reverse_words>
  MAKE_FUNCTION 0
  STORE_NAME reverse_words
  RETURN_CONST None
END
CODE reverse_words(s)
  RESUME 0
  LOAD_CONST ' '
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL NULL + reversed
  LOAD_FAST s
  LOAD_ATTR NULL|self + split
  CALL 0
  CALL 1
  CALL 1
  RETURN_VALUE
END

def reverse_words(s):
    return ' '.join(reversed(s.split()))

Prompt: Write a function to reverse words in a given string.

assert reverse_words("python program")==("program python")

assert reverse_words("java language")==("language java")

assert reverse_words("indian man")==("man indian")


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code prime_num>
  MAKE_FUNCTION 0
  STORE_NAME prime_num
  RETURN_CONST None
END
CODE prime_num(num)
  RESUME 0
  LOAD_FAST num
  LOAD_CONST 1
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_FAST num
  LOAD_CONST 2
  BINARY_OP //
  CALL 2
  GET_ITER
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST num
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  POP_TOP
  RETURN_CONST False
L1:
  POP_TOP
  RETURN_CONST True
L2:
  END_FOR
  RETURN_CONST None
L3:
  RETURN_CONST False
END

def prime_num(num):
    if num >= 1:
        for i in range(2, num // 2):
            if num % i == 0:
                return False
            else:
                return True
    else:
        return False

Prompt: Write a function to check if the given integer is a prime number.

assert prime_num(13)==True
assert prime_num(7)==True
assert prime_num(-1010)==False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code radian_degree>
  MAKE_FUNCTION 0
  STORE_NAME radian_degree
  RETURN_CONST None
END
CODE radian_degree(degree)
  RESUME 0
  LOAD_FAST degree
  LOAD_GLOBAL math
  LOAD_ATTR pi
  LOAD_CONST 180
  BINARY_OP /
  BINARY_OP *
  STORE_FAST radian
  LOAD_FAST radian
  RETURN_VALUE
END

import math

def radian_degree(degree):
    radian = degree * (math.pi / 180)
    return radian

Prompt: Write a function to convert degrees to radians.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code bell_Number>
  MAKE_FUNCTION 0
  STORE_NAME bell_Number
  RETURN_CONST None
END
CODE bell_Number(n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR j
  LOAD_FAST_AND_CLEAR i
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L7
  STORE_FAST j
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L3:
  BUILD_LIST 0
  SWAP 2
L4:
  FOR_ITER L5
  STORE_FAST i
  LOAD_CONST 0
  LIST_APPEND 2
  JUMP_BACKWARD L4
L5:
  END_FOR
L6:
  SWAP 2
  STORE_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L2
L7:
  END_FOR
L8:
  STORE_FAST bell
  STORE_FAST j
  STORE_FAST i
  LOAD_CONST 1
  LOAD_FAST bell
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 0
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L9:
  FOR_ITER L12
  STORE_FAST i
  LOAD_FAST bell
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST bell
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_CONST 0
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L10:
  FOR_ITER L11
  STORE_FAST j
  LOAD_FAST bell
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST j
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST bell
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST j
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST bell
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST j
  STORE_SUBSCR
  JUMP_BACKWARD L10
L11:
  END_FOR
  JUMP_BACKWARD L9
L12:
  END_FOR
  LOAD_FAST bell
  LOAD_FAST n
  BINARY_SUBSCR
  LOAD_CONST 0
  BINARY_SUBSCR
  RETURN_VALUE
L13:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
L14:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST i
  STORE_FAST j
  RERAISE 0
  EXC try=L1..L3 -> handler=L14 depth=3 lasti=False
  EXC try=L3..L6 -> handler=L13 depth=6 lasti=False
  EXC try=L6..L8 -> handler=L14 depth=3 lasti=False
  EXC try=L13..L14 -> handler=L14 depth=3 lasti=False
END

def bell_Number(n):
    bell = [[0 for i in range(n + 1)] for j in range(n + 1)]
    bell[0][0] = 1
    for i in range(1, n + 1):
        bell[i][0] = bell[i - 1][i - 1]
        for j in range(1, i + 1):
            bell[i][j] = bell[i - 1][j - 1] + bell[i][j - 1]
    return bell[n][0]

Prompt: Write a python function to find nth bell number.

assert bell_Number(2) == 2
assert bell_Number(3) == 5
assert bell_Number(4) == 15


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_kth_element>
  MAKE_FUNCTION 0
  STORE_NAME remove_kth_element
  RETURN_CONST None
END
CODE remove_kth_element(list1, L)
  RESUME 0
  LOAD_FAST list1
  LOAD_CONST None
  LOAD_FAST L
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SLICE
  LOAD_FAST list1
  LOAD_FAST L
  LOAD_CONST None
  BINARY_SLICE
  BINARY_OP +
  RETURN_VALUE
END

def remove_kth_element(list1, L):
    return list1[:L - 1] + list1[L:]

Prompt: Write a python function to remove the k'th element from a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code merge>
  MAKE_FUNCTION 0
  STORE_NAME merge
  RETURN_CONST None
END
CODE merge(lst)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + zip
  LOAD_FAST lst
  CALL_FUNCTION_EX 0
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR ele
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST ele
  LOAD_GLOBAL NULL + list
  LOAD_FAST ele
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 2
  STORE_FAST ele
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ele
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=2 lasti=False
END

def merge(lst):
    return [list(ele) for ele in list(zip(*lst))]

Prompt: Write a python function to merge the first and last elements separately in a list of lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code maximum_value>
  MAKE_FUNCTION 0
  STORE_NAME maximum_value
  RETURN_CONST None
END
CODE maximum_value(test_list)
  RESUME 0
  LOAD_FAST test_list
  GET_ITER
  LOAD_FAST_AND_CLEAR key
  LOAD_FAST_AND_CLEAR lst
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST lst
  LOAD_FAST key
  LOAD_GLOBAL NULL + max
  LOAD_FAST lst
  CALL 1
  BUILD_TUPLE 2
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST res
  STORE_FAST key
  STORE_FAST lst
  LOAD_FAST res
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST lst
  STORE_FAST key
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END

def maximum_value(test_list):
    res = [(key, max(lst)) for key, lst in test_list]
    return res

Prompt: Write a function to find the maximum value in record list as tuple attribute in the given tuple list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code cummulative_sum>
  MAKE_FUNCTION 0
  STORE_NAME cummulative_sum
  RETURN_CONST None
END
CODE cummulative_sum(test_list)
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_GLOBAL NULL + map
  LOAD_GLOBAL sum
  LOAD_FAST test_list
  CALL 2
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def cummulative_sum(test_list):
    res = sum(map(sum, test_list))
    return res

Prompt: Write a function to find the cumulative sum of all the values that are present in the given tuple list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code average_tuple>
  MAKE_FUNCTION 0
  STORE_NAME average_tuple
  RETURN_CONST None
END
CODE average_tuple(nums)
  RESUME 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST nums
  CALL_FUNCTION_EX 0
  GET_ITER
  LOAD_FAST_AND_CLEAR x
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST x
  LOAD_GLOBAL NULL + sum
  LOAD_FAST x
  CALL 1
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  BINARY_OP /
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST result
  STORE_FAST x
  LOAD_FAST result
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST x
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=2 lasti=False
END

def average_tuple(nums):
    result = [sum(x) / len(x) for x in zip(*nums)]
    return result

Prompt: Write a function to find average value of the numbers in a given tuple of tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code tuple_modulo>
  MAKE_FUNCTION 0
  STORE_NAME tuple_modulo
  RETURN_CONST None
END
CODE tuple_modulo(test_tup1, test_tup2)
  RESUME 0
  LOAD_GLOBAL NULL + tuple
  LOAD_CONST <code tuple_modulo.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST test_tup1
  LOAD_FAST test_tup2
  CALL 2
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END
CODE tuple_modulo.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST ele1
  STORE_FAST ele2
  LOAD_FAST ele1
  LOAD_FAST ele2
  BINARY_OP %
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def tuple_modulo(test_tup1, test_tup2):
    res = tuple((ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2)))
    return res

Prompt: Write a function to perfom the modulo of tuple elements in the given two tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code div_list>
  MAKE_FUNCTION 0
  STORE_NAME div_list
  RETURN_CONST None
END
CODE div_list(nums1, nums2)
  RESUME 0
  LOAD_GLOBAL NULL + map
  LOAD_CONST <code div_list.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST nums1
  LOAD_FAST nums2
  CALL 3
  STORE_FAST result
  LOAD_GLOBAL NULL + list
  LOAD_FAST result
  CALL 1
  RETURN_VALUE
END
CODE div_list.<locals>.<lambda>(x, y)
  RESUME 0
  LOAD_FAST x
  LOAD_FAST y
  BINARY_OP /
  RETURN_VALUE
END

def div_list(nums1, nums2):
    result = map(lambda x, y: x / y, nums1, nums2)
    return list(result)

Prompt: Write a function to divide two lists using map and lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code move_num>
  MAKE_FUNCTION 0
  STORE_NAME move_num
  RETURN_CONST None
END
CODE move_num(test_str)
  RESUME 0
  LOAD_CONST ''
  STORE_FAST res
  LOAD_CONST ''
  STORE_FAST dig
  LOAD_FAST test_str
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_ATTR NULL|self + isdigit
  CALL 0
  POP_JUMP_IF_FALSE L2
  LOAD_FAST dig
  LOAD_FAST ele
  BINARY_OP +=
  STORE_FAST dig
  JUMP_BACKWARD L1
L2:
  LOAD_FAST res
  LOAD_FAST ele
  BINARY_OP +=
  STORE_FAST res
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST res
  LOAD_FAST dig
  BINARY_OP +=
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def move_num(test_str):
    res = ''
    dig = ''
    for ele in test_str:
        if ele.isdigit():
            dig += ele
        else:
            res += ele
    res += dig
    return res

Prompt: Write a function to move all the numbers in it to the given string.

assert move_num('I1love143you55three3000thousand') == 'Iloveyouthreethousand1143553000'

assert move_num('Avengers124Assemble') == 'AvengersAssemble124'

assert move_num('Its11our12path13to14see15things16do17things') == 'Itsourpathtoseethingsdothings11121314151617'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code increment_numerics>
  MAKE_FUNCTION 0
  STORE_NAME increment_numerics
  RETURN_CONST None
END
CODE increment_numerics(test_list, K)
  RESUME 0
  LOAD_FAST test_list
  GET_ITER
  LOAD_FAST_AND_CLEAR ele
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_ATTR NULL|self + isdigit
  CALL 0
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + str
  LOAD_GLOBAL NULL + int
  LOAD_FAST ele
  CALL 1
  LOAD_FAST K
  BINARY_OP +
  CALL 1
  JUMP_FORWARD L4
L3:
  LOAD_FAST ele
L4:
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST res
  STORE_FAST ele
  LOAD_FAST res
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ele
  RERAISE 0
  EXC try=L1..L6 -> handler=L7 depth=2 lasti=False
END

def increment_numerics(test_list, K):
    res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list]
    return res

Prompt: Write a function to increment the numeric values in the given strings by k.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_median>
  MAKE_FUNCTION 0
  STORE_NAME get_median
  RETURN_CONST None
END
CODE get_median(arr1, arr2, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST i
  LOAD_CONST 0
  STORE_FAST j
  LOAD_CONST -1
  STORE_FAST m1
  LOAD_CONST -1
  STORE_FAST m2
  LOAD_CONST 0
  STORE_FAST count
  LOAD_FAST count
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP <
  POP_JUMP_IF_FALSE L6
L1:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
  LOAD_FAST i
  LOAD_FAST n
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST m2
  STORE_FAST m1
  LOAD_FAST arr2
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST m2
  JUMP_FORWARD L6
L2:
  LOAD_FAST j
  LOAD_FAST n
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST m2
  STORE_FAST m1
  LOAD_FAST arr1
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST m2
  JUMP_FORWARD L6
L3:
  LOAD_FAST arr1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr2
  LOAD_FAST j
  BINARY_SUBSCR
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
  LOAD_FAST m2
  STORE_FAST m1
  LOAD_FAST arr1
  LOAD_FAST i
  BINARY_SUBSCR
  STORE_FAST m2
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST i
  JUMP_FORWARD L5
L4:
  LOAD_FAST m2
  STORE_FAST m1
  LOAD_FAST arr2
  LOAD_FAST j
  BINARY_SUBSCR
  STORE_FAST m2
  LOAD_FAST j
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST j
L5:
  LOAD_FAST count
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  COMPARE_OP <
  POP_JUMP_IF_FALSE L6
  JUMP_BACKWARD L1
L6:
  LOAD_FAST m1
  LOAD_FAST m2
  BINARY_OP +
  LOAD_CONST 2
  BINARY_OP /
  RETURN_VALUE
END

def get_median(arr1, arr2, n):
    i = 0
    j = 0
    m1 = -1
    m2 = -1
    count = 0
    while count < n + 1:
        count += 1
        if i == n:
            m1 = m2
            m2 = arr2[0]
            break
        elif j == n:
            m1 = m2
            m2 = arr1[0]
            break
        if arr1[i] <= arr2[j]:
            m1 = m2
            m2 = arr1[i]
            i += 1
        else:
            m1 = m2
            m2 = arr2[j]
            j += 1
    return (m1 + m2) / 2

Prompt: Write a function to find the median of two sorted arrays of same size.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code nth_nums>
  MAKE_FUNCTION 0
  STORE_NAME nth_nums
  RETURN_CONST None
END
CODE nth_nums(nums, n)
  MAKE_CELL n
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + map
  LOAD_CLOSURE n
  BUILD_TUPLE 1
  LOAD_CONST <code nth_nums.<locals>.<lambda>>
  MAKE_FUNCTION closure
  LOAD_FAST nums
  CALL 2
  CALL 1
  STORE_FAST nth_nums
  LOAD_FAST nth_nums
  RETURN_VALUE
END
CODE nth_nums.<locals>.<lambda>(x)
  COPY_FREE_VARS 1
  RESUME 0
  LOAD_FAST x
  LOAD_DEREF n
  BINARY_OP **
  RETURN_VALUE
END

def nth_nums(nums, n):
    nth_nums = list(map(lambda x: x ** n, nums))
    return nth_nums

Prompt: Write a function to find the n-th power of individual elements in a list using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code swap_List>
  MAKE_FUNCTION 0
  STORE_NAME swap_List
  RETURN_CONST None
END
CODE swap_List(newList)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST newList
  CALL 1
  STORE_FAST size
  LOAD_FAST newList
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST temp
  LOAD_FAST newList
  LOAD_FAST size
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST newList
  LOAD_CONST 0
  STORE_SUBSCR
  LOAD_FAST temp
  LOAD_FAST newList
  LOAD_FAST size
  LOAD_CONST 1
  BINARY_OP -
  STORE_SUBSCR
  LOAD_FAST newList
  RETURN_VALUE
END

def swap_List(newList):
    size = len(newList)
    temp = newList[0]
    newList[0] = newList[size - 1]
    newList[size - 1] = temp
    return newList

Prompt: Write a python function to interchange first and last elements in a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code triangle_area>
  MAKE_FUNCTION 0
  STORE_NAME triangle_area
  RETURN_CONST None
END
CODE triangle_area(r)
  RESUME 0
  LOAD_FAST r
  LOAD_CONST 0
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  RETURN_CONST -1
L1:
  LOAD_FAST r
  LOAD_FAST r
  BINARY_OP *
  RETURN_VALUE
END

def triangle_area(r):
    if r < 0:
        return -1
    return r * r

Prompt: Write a python function to find the largest triangle that can be inscribed in the semicircle.

assert triangle_area(0) == 0
assert triangle_area(-1) == -1
assert triangle_area(2) == 4


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 1000
  STORE_NAME MAX
  LOAD_CONST <code replace_spaces>
  MAKE_FUNCTION 0
  STORE_NAME replace_spaces
  RETURN_CONST None
END
CODE replace_spaces(string)
  RESUME 0
  LOAD_FAST string
  LOAD_ATTR NULL|self + strip
  CALL 0
  STORE_FAST string
  LOAD_GLOBAL NULL + len
  LOAD_FAST string
  CALL 1
  STORE_FAST i
  LOAD_FAST string
  LOAD_ATTR NULL|self + count
  LOAD_CONST ' '
  CALL 1
  STORE_FAST space_count
  LOAD_FAST i
  LOAD_FAST space_count
  LOAD_CONST 2
  BINARY_OP *
  BINARY_OP +
  STORE_FAST new_length
  LOAD_FAST new_length
  LOAD_GLOBAL MAX
  COMPARE_OP >
  POP_JUMP_IF_FALSE L1
  RETURN_CONST -1
L1:
  LOAD_FAST new_length
  LOAD_CONST 1
  BINARY_OP -
  STORE_FAST index
  LOAD_GLOBAL NULL + list
  LOAD_FAST string
  CALL 1
  STORE_FAST string
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP -
  LOAD_FAST new_length
  LOAD_CONST 2
  BINARY_OP -
  CALL 2
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST f
  LOAD_FAST string
  LOAD_ATTR NULL|self + append
  LOAD_CONST '0'
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST 0
  LOAD_CONST -1
  CALL 3
  GET_ITER
L4:
  FOR_ITER L6
  STORE_FAST j
  LOAD_FAST string
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST ' '
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  LOAD_CONST '0'
  LOAD_FAST string
  LOAD_FAST index
  STORE_SUBSCR
  LOAD_CONST '2'
  LOAD_FAST string
  LOAD_FAST index
  LOAD_CONST 1
  BINARY_OP -
  STORE_SUBSCR
  LOAD_CONST '%'
  LOAD_FAST string
  LOAD_FAST index
  LOAD_CONST 2
  BINARY_OP -
  STORE_SUBSCR
  LOAD_FAST index
  LOAD_CONST 3
  BINARY_OP -
  STORE_FAST index
  JUMP_BACKWARD L4
L5:
  LOAD_FAST string
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_FAST string
  LOAD_FAST index
  STORE_SUBSCR
  LOAD_FAST index
  LOAD_CONST 1
  BINARY_OP -=
  STORE_FAST index
  JUMP_BACKWARD L4
L6:
  END_FOR
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_FAST string
  CALL 1
  RETURN_VALUE
END

MAX = 1000

def replace_spaces(string):
    string = string.strip()
    i = len(string)
    space_count = string.count(' ')
    new_length = i + space_count * 2
    if new_length > MAX:
        return -1
    index = new_length - 1
    string = list(string)
    for f in range(i - 2, new_length - 2):
        string.append('0')
    for j in range(i - 1, 0, -1):
        if string[j] == ' ':
            string[index] = '0'
            string[index - 1] = '2'
            string[index - 2] = '%'
            index = index - 3
        else:
            string[index] = string[j]
            index -= 1
    return ''.join(string)

Prompt: Write a function to replace all spaces in the given string with character * list item * list item * list item * list item '%20'.

assert replace_spaces("My Name is Dawood") == 'My%20Name%20is%20Dawood'

assert replace_spaces("I am a Programmer") == 'I%20am%20a%20Programmer'

assert replace_spaces("I love Coding") == 'I%20love%20Coding'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Split>
  MAKE_FUNCTION 0
  STORE_NAME Split
  RETURN_CONST None
END
CODE Split(list)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST ev_li
  LOAD_FAST list
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST ev_li
  LOAD_ATTR NULL|self + append
  LOAD_FAST i
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST ev_li
  RETURN_VALUE
END

def Split(list):
    ev_li = []
    for i in list:
        if i % 2 == 0:
            ev_li.append(i)
    return ev_li

Prompt: Write a python function to find even numbers from a mixed list.


Input:
CODE <module>()
  RESUME 0
  BUILD_LIST 0
  BUILD_TUPLE 1
  LOAD_CONST <code adjac>
  MAKE_FUNCTION defaults
  STORE_NAME adjac
  LOAD_CONST <code get_coordinates>
  MAKE_FUNCTION 0
  STORE_NAME get_coordinates
  RETURN_CONST None
END
CODE adjac(ele, sub)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST ele
  POP_JUMP_IF_TRUE L2
  LOAD_FAST sub
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  RETURN_CONST None
L2:
  LOAD_GLOBAL NULL + range
  LOAD_FAST ele
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP -
  LOAD_FAST ele
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 2
  BINARY_OP +
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR j
  LOAD_FAST_AND_CLEAR idx
  SWAP 3
L3:
  BUILD_LIST 0
  SWAP 2
L4:
  FOR_ITER L7
  STORE_FAST j
  LOAD_GLOBAL NULL + adjac
  LOAD_FAST ele
  LOAD_CONST 1
  LOAD_CONST None
  BINARY_SLICE
  LOAD_FAST sub
  LOAD_FAST j
  BUILD_LIST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L5:
  FOR_ITER L6
  STORE_FAST idx
  LOAD_FAST idx
  LIST_APPEND 3
  JUMP_BACKWARD L5
L6:
  END_FOR
  JUMP_BACKWARD L4
L7:
  END_FOR
L8:
  SWAP 3
  STORE_FAST idx
  STORE_FAST j
  GET_YIELD_FROM_ITER
  LOAD_CONST None
L9:
  SEND L12
L10:
  YIELD_VALUE 2
L11:
  RESUME 2
  JUMP_BACKWARD_NO_INTERRUPT L9
L12:
  END_SEND
  POP_TOP
  RETURN_CONST None
L13:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST idx
  STORE_FAST j
  RERAISE 0
L14:
  CLEANUP_THROW
L15:
  JUMP_BACKWARD L12
L16:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L3 -> handler=L16 depth=0 lasti=True
  EXC try=L3..L8 -> handler=L13 depth=3 lasti=False
  EXC try=L8..L10 -> handler=L16 depth=0 lasti=True
  EXC try=L10..L11 -> handler=L14 depth=2 lasti=False
  EXC try=L11..L15 -> handler=L16 depth=0 lasti=True
END
CODE get_coordinates(test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + adjac
  LOAD_FAST test_tup
  CALL 1
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def adjac(ele, sub=[]):
    if not ele:
        yield sub
    else:
        yield from [idx for j in range(ele[0] - 1, ele[0] + 2) for idx in adjac(ele[1:], sub + [j])]

def get_coordinates(test_tup):
    res = list(adjac(test_tup))
    return res

Prompt: Write a function to extract all the adjacent coordinates of the given coordinate tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST 'Python Exercises'
  STORE_NAME text
  LOAD_CONST <code replace_spaces>
  MAKE_FUNCTION 0
  STORE_NAME replace_spaces
  RETURN_CONST None
END
CODE replace_spaces(text)
  RESUME 0
  LOAD_FAST text
  LOAD_ATTR NULL|self + replace
  LOAD_CONST ' '
  LOAD_CONST '_'
  CALL 2
  STORE_FAST text
  LOAD_FAST text
  RETURN_VALUE
END

import re
text = 'Python Exercises'

def replace_spaces(text):
    text = text.replace(' ', '_')
    return text
    text = text.replace('_', ' ')
    return text

Prompt: Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.

assert replace_spaces('Jumanji The Jungle') == 'Jumanji_The_Jungle'

assert replace_spaces('The Avengers') == 'The_Avengers'

assert replace_spaces('Fast and Furious') == 'Fast_and_Furious'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code move_zero>
  MAKE_FUNCTION 0
  STORE_NAME move_zero
  RETURN_CONST None
END
CODE move_zero(num_list)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST num_list
  LOAD_ATTR NULL|self + count
  LOAD_CONST 0
  CALL 1
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_CONST 0
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST a
  STORE_FAST i
  LOAD_FAST num_list
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L5:
  BUILD_LIST 0
  SWAP 2
L6:
  FOR_ITER L9
  STORE_FAST i
  LOAD_FAST i
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L8
L7:
  JUMP_BACKWARD L6
L8:
  LOAD_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L6
L9:
  END_FOR
L10:
  STORE_FAST x
  STORE_FAST i
  LOAD_FAST x
  LOAD_ATTR NULL|self + extend
  LOAD_FAST a
  CALL 1
  POP_TOP
  LOAD_FAST x
  RETURN_VALUE
L11:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
L12:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L11 depth=2 lasti=False
  EXC try=L5..L7 -> handler=L12 depth=2 lasti=False
  EXC try=L8..L10 -> handler=L12 depth=2 lasti=False
END

def move_zero(num_list):
    a = [0 for i in range(num_list.count(0))]
    x = [i for i in num_list if i != 0]
    x.extend(a)
    return x

Prompt: Write a python function to move all zeroes to the end of the given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code pair_OR_Sum>
  MAKE_FUNCTION 0
  STORE_NAME pair_OR_Sum
  RETURN_CONST None
END
CODE pair_OR_Sum(arr, n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST ans
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST n
  CALL 2
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  LOAD_FAST n
  CALL 2
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST j
  LOAD_FAST ans
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  BINARY_OP ^
  BINARY_OP +
  STORE_FAST ans
  JUMP_BACKWARD L2
L3:
  END_FOR
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST ans
  RETURN_VALUE
END

def pair_OR_Sum(arr, n):
    ans = 0
    for i in range(0, n):
        for j in range(i + 1, n):
            ans = ans + (arr[i] ^ arr[j])
    return ans

Prompt: Write a python function to find the sum of xor of all pairs of numbers in the given array.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code even_Power_Sum>
  MAKE_FUNCTION 0
  STORE_NAME even_Power_Sum
  RETURN_CONST None
END
CODE even_Power_Sum(n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST sum
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_CONST 2
  LOAD_FAST i
  BINARY_OP *
  STORE_FAST j
  LOAD_FAST sum
  LOAD_FAST j
  LOAD_FAST j
  BINARY_OP *
  LOAD_FAST j
  BINARY_OP *
  LOAD_FAST j
  BINARY_OP *
  BINARY_OP +
  STORE_FAST sum
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST sum
  RETURN_VALUE
END

def even_Power_Sum(n):
    sum = 0
    for i in range(1, n + 1):
        j = 2 * i
        sum = sum + j * j * j * j
    return sum

Prompt: Write a python function to find the sum of fourth power of first n even natural numbers.

assert even_Power_Sum(2) == 272
assert even_Power_Sum(3) == 1568
assert even_Power_Sum(4) == 5664


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME heapq
  STORE_NAME hq
  LOAD_CONST <code heap_sort>
  MAKE_FUNCTION 0
  STORE_NAME heap_sort
  RETURN_CONST None
END
CODE heap_sort(iterable)
  RESUME 0
  BUILD_LIST 0
  STORE_FAST h
  LOAD_FAST iterable
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST value
  LOAD_GLOBAL NULL + hq
  LOAD_ATTR heappush
  LOAD_FAST h
  LOAD_FAST value
  CALL 2
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST h
  CALL 1
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L3:
  BUILD_LIST 0
  SWAP 2
L4:
  FOR_ITER L5
  STORE_FAST i
  LOAD_GLOBAL NULL + hq
  LOAD_ATTR heappop
  LOAD_FAST h
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L4
L5:
  END_FOR
L6:
  SWAP 2
  STORE_FAST i
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L3..L6 -> handler=L7 depth=2 lasti=False
END

import heapq as hq

def heap_sort(iterable):
    h = []
    for value in iterable:
        hq.heappush(h, value)
    return [hq.heappop(h) for i in range(len(h))]

Prompt: Write a function to push all values into a heap and then pop off the smallest values one at a time.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Check_Solution>
  MAKE_FUNCTION 0
  STORE_NAME Check_Solution
  RETURN_CONST None
END
CODE Check_Solution(a, b, c)
  RESUME 0
  LOAD_FAST a
  LOAD_FAST c
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Yes'
L1:
  RETURN_CONST 'No'
END

def Check_Solution(a, b, c):
    if a == c:
        return 'Yes'
    else:
        return 'No'

Prompt: Write a python function to check if roots of a quadratic equation are reciprocal of each other or not.

assert Check_Solution(2,0,2) == "Yes"
assert Check_Solution(2,-5,2) == "Yes"
assert Check_Solution(1,2,3) == "No"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code noprofit_noloss>
  MAKE_FUNCTION 0
  STORE_NAME noprofit_noloss
  RETURN_CONST None
END
CODE noprofit_noloss(actual_cost, sale_amount)
  RESUME 0
  LOAD_FAST sale_amount
  LOAD_FAST actual_cost
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

def noprofit_noloss(actual_cost, sale_amount):
    if sale_amount == actual_cost:
        return True
    else:
        return False

Prompt: Write a function to check whether the given amount has no profit and no loss


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sample_nam>
  MAKE_FUNCTION 0
  STORE_NAME sample_nam
  RETURN_CONST None
END
CODE sample_nam(sample_names)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + filter
  LOAD_CONST <code sample_nam.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST sample_names
  CALL 2
  CALL 1
  STORE_FAST sample_names
  LOAD_GLOBAL NULL + len
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_FAST sample_names
  CALL 1
  CALL 1
  RETURN_VALUE
END
CODE sample_nam.<locals>.<lambda>(el)
  RESUME 0
  LOAD_FAST el
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + isupper
  CALL 0
  COPY 1
  POP_JUMP_IF_FALSE L1
  POP_TOP
  LOAD_FAST el
  LOAD_CONST 1
  LOAD_CONST None
  BINARY_SLICE
  LOAD_ATTR NULL|self + islower
  CALL 0
L1:
  RETURN_VALUE
END

def sample_nam(sample_names):
    sample_names = list(filter(lambda el: el[0].isupper() and el[1:].islower(), sample_names))
    return len(''.join(sample_names))

Prompt: Write a function to sum the length of the names of a given list of names after removing the names that start with a lowercase letter.

assert sample_nam(['sally', 'Dylan', 'rebecca', 'Diana', 'Joanne', 'keith'])==16

assert sample_nam(["php", "res", "Python", "abcd", "Java", "aaa"])==10

assert sample_nam(["abcd", "Python", "abba", "aba"])==6


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code remove_parenthesis>
  MAKE_FUNCTION 0
  STORE_NAME remove_parenthesis
  RETURN_CONST None
END
CODE remove_parenthesis(items)
  RESUME 0
  LOAD_FAST items
  GET_ITER
  FOR_ITER L1
  STORE_FAST item
  LOAD_GLOBAL NULL + re
  LOAD_ATTR sub
  LOAD_CONST ' ?\\([^)]+\\)'
  LOAD_CONST ''
  LOAD_FAST item
  CALL 3
  SWAP 2
  POP_TOP
  RETURN_VALUE
L1:
  END_FOR
  RETURN_CONST None
END

import re

def remove_parenthesis(items):
    for item in items:
        return re.sub(' ?\\([^)]+\\)', '', item)

Prompt: Write a function to remove the parenthesis area in a string.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code is_nonagonal>
  MAKE_FUNCTION 0
  STORE_NAME is_nonagonal
  RETURN_CONST None
END
CODE is_nonagonal(n)
  RESUME 0
  LOAD_GLOBAL NULL + int
  LOAD_FAST n
  LOAD_CONST 7
  LOAD_FAST n
  BINARY_OP *
  LOAD_CONST 5
  BINARY_OP -
  BINARY_OP *
  LOAD_CONST 2
  BINARY_OP /
  CALL 1
  RETURN_VALUE
END

def is_nonagonal(n):
    return int(n * (7 * n - 5) / 2)

Prompt: Write a function to find the nth nonagonal number.

assert is_nonagonal(10) == 325
assert is_nonagonal(15) == 750
assert is_nonagonal(18) == 1089


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_similar_row>
  MAKE_FUNCTION 0
  STORE_NAME remove_similar_row
  RETURN_CONST None
END
CODE remove_similar_row(test_list)
  RESUME 0
  LOAD_GLOBAL NULL + set
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST test_list
  GET_ITER
  LOAD_FAST_AND_CLEAR sub
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST sub
  LOAD_GLOBAL NULL + tuple
  LOAD_GLOBAL NULL + sorted
  LOAD_GLOBAL NULL + set
  LOAD_FAST sub
  CALL 1
  CALL 1
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 2
  STORE_FAST sub
  CALL 1
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST sub
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=6 lasti=False
END

def remove_similar_row(test_list):
    res = set(sorted([tuple(sorted(set(sub))) for sub in test_list]))
    return res

Prompt: Write a function to remove similar rows from the given tuple matrix.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST <code text_match_wordz_middle>
  MAKE_FUNCTION 0
  STORE_NAME text_match_wordz_middle
  RETURN_CONST None
END
CODE text_match_wordz_middle(text)
  RESUME 0
  LOAD_CONST '\\Bz\\B'
  STORE_FAST patterns
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_FAST patterns
  LOAD_FAST text
  CALL 2
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Found a match!'
L1:
  RETURN_CONST 'Not matched!'
END

import re

def text_match_wordz_middle(text):
    patterns = '\\Bz\\B'
    if re.search(patterns, text):
        return 'Found a match!'
    else:
        return 'Not matched!'

Prompt: Write a function that matches a word containing 'z', not at the start or end of the word.

assert text_match_wordz_middle("pythonzabc.")==('Found a match!')

assert text_match_wordz_middle("xyzabc.")==('Found a match!')

assert text_match_wordz_middle("  lang  .")==('Not matched!')


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code reverse_Array_Upto_K>
  MAKE_FUNCTION 0
  STORE_NAME reverse_Array_Upto_K
  RETURN_CONST None
END
CODE reverse_Array_Upto_K(input, k)
  RESUME 0
  LOAD_FAST input
  LOAD_FAST k
  LOAD_CONST 1
  BINARY_OP -
  LOAD_CONST None
  LOAD_CONST -1
  BUILD_SLICE 3
  BINARY_SUBSCR
  LOAD_FAST input
  LOAD_FAST k
  LOAD_CONST None
  BINARY_SLICE
  BINARY_OP +
  RETURN_VALUE
END

def reverse_Array_Upto_K(input, k):
    return input[k - 1::-1] + input[k:]

Prompt: Write a python function to reverse an array upto a given position.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code get_product>
  MAKE_FUNCTION 0
  STORE_NAME get_product
  LOAD_CONST <code find_k_product>
  MAKE_FUNCTION 0
  STORE_NAME find_k_product
  RETURN_CONST None
END
CODE get_product(val)
  RESUME 0
  LOAD_CONST 1
  STORE_FAST res
  LOAD_FAST val
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST ele
  LOAD_FAST res
  LOAD_FAST ele
  BINARY_OP *=
  STORE_FAST res
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
END
CODE find_k_product(test_list, K)
  RESUME 0
  LOAD_GLOBAL NULL + get_product
  LOAD_FAST test_list
  GET_ITER
  LOAD_FAST_AND_CLEAR sub
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST sub
  LOAD_FAST sub
  LOAD_FAST K
  BINARY_SUBSCR
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  SWAP 2
  STORE_FAST sub
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST sub
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=4 lasti=False
END

def get_product(val):
    res = 1
    for ele in val:
        res *= ele
    return res

def find_k_product(test_list, K):
    res = get_product([sub[K] for sub in test_list])
    return res

Prompt: Write a function to find the product of it’s kth index in the given tuples.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code No_of_cubes>
  MAKE_FUNCTION 0
  STORE_NAME No_of_cubes
  RETURN_CONST None
END
CODE No_of_cubes(N, K)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST No
  LOAD_FAST N
  LOAD_FAST K
  BINARY_OP -
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST No
  LOAD_GLOBAL NULL + pow
  LOAD_FAST No
  LOAD_CONST 3
  CALL 2
  STORE_FAST No
  LOAD_FAST No
  RETURN_VALUE
END

def No_of_cubes(N, K):
    No = 0
    No = N - K + 1
    No = pow(No, 3)
    return No

Prompt: Write a python function to count number of cubes of size k in a cube of size n.

assert No_of_cubes(2,1) == 8
assert No_of_cubes(5,2) == 64
assert No_of_cubes(1,1) == 1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('zip_longest', 'chain', 'tee')
  IMPORT_NAME itertools
  IMPORT_FROM zip_longest
  STORE_NAME zip_longest
  IMPORT_FROM chain
  STORE_NAME chain
  IMPORT_FROM tee
  STORE_NAME tee
  POP_TOP
  LOAD_CONST <code exchange_elements>
  MAKE_FUNCTION 0
  STORE_NAME exchange_elements
  RETURN_CONST None
END
CODE exchange_elements(lst)
  RESUME 0
  LOAD_GLOBAL NULL + tee
  LOAD_GLOBAL NULL + iter
  LOAD_FAST lst
  CALL 1
  LOAD_CONST 2
  CALL 2
  UNPACK_SEQUENCE 2
  STORE_FAST lst1
  STORE_FAST lst2
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + chain
  LOAD_ATTR from_iterable
  LOAD_GLOBAL NULL + zip_longest
  LOAD_FAST lst
  LOAD_CONST 1
  LOAD_CONST None
  LOAD_CONST 2
  BUILD_SLICE 3
  BINARY_SUBSCR
  LOAD_FAST lst
  LOAD_CONST None
  LOAD_CONST None
  LOAD_CONST 2
  BUILD_SLICE 3
  BINARY_SUBSCR
  CALL 2
  CALL 1
  CALL 1
  RETURN_VALUE
END

from itertools import zip_longest, chain, tee

def exchange_elements(lst):
    lst1, lst2 = tee(iter(lst), 2)
    return list(chain.from_iterable(zip_longest(lst[1::2], lst[::2])))

Prompt: Write a function to exchange the position of every n-th value with (n+1)th value and (n+1)th value with n-th value in a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code are_Equal>
  MAKE_FUNCTION 0
  STORE_NAME are_Equal
  RETURN_CONST None
END
CODE are_Equal(arr1, arr2, n, m)
  RESUME 0
  LOAD_FAST n
  LOAD_FAST m
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  LOAD_FAST arr1
  LOAD_ATTR NULL|self + sort
  CALL 0
  POP_TOP
  LOAD_FAST arr2
  LOAD_ATTR NULL|self + sort
  CALL 0
  POP_TOP
  LOAD_GLOBAL NULL + range
  LOAD_CONST 0
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  CALL 2
  GET_ITER
L2:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST arr1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr2
  LOAD_FAST i
  BINARY_SUBSCR
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  POP_TOP
  RETURN_CONST False
L4:
  END_FOR
  RETURN_CONST True
END

def are_Equal(arr1, arr2, n, m):
    if n != m:
        return False
    arr1.sort()
    arr2.sort()
    for i in range(0, n - 1):
        if arr1[i] != arr2[i]:
            return False
    return True

Prompt: Write a python function to check whether the given two arrays are equal or not.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_subset>
  MAKE_FUNCTION 0
  STORE_NAME check_subset
  RETURN_CONST None
END
CODE check_subset(test_tup1, test_tup2)
  RESUME 0
  LOAD_GLOBAL NULL + set
  LOAD_FAST test_tup2
  CALL 1
  LOAD_ATTR NULL|self + issubset
  LOAD_FAST test_tup1
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def check_subset(test_tup1, test_tup2):
    res = set(test_tup2).issubset(test_tup1)
    return res

Prompt: Write a function to check if one tuple is a subset of another tuple.

assert check_subset((1, 2, 3, 4), (5, 6)) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code matrix_to_list>
  MAKE_FUNCTION 0
  STORE_NAME matrix_to_list
  RETURN_CONST None
END
CODE matrix_to_list(test_list)
  RESUME 0
  LOAD_FAST test_list
  GET_ITER
  LOAD_FAST_AND_CLEAR sub
  LOAD_FAST_AND_CLEAR ele
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST sub
  LOAD_FAST sub
  GET_ITER
L3:
  FOR_ITER L4
  STORE_FAST ele
  LOAD_FAST ele
  LIST_APPEND 3
  JUMP_BACKWARD L3
L4:
  END_FOR
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST temp
  STORE_FAST sub
  STORE_FAST ele
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + zip
  LOAD_FAST temp
  CALL_FUNCTION_EX 0
  CALL 1
  STORE_FAST res
  LOAD_GLOBAL NULL + str
  LOAD_FAST res
  CALL 1
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST ele
  STORE_FAST sub
  RERAISE 0
  EXC try=L1..L6 -> handler=L7 depth=3 lasti=False
END

def matrix_to_list(test_list):
    temp = [ele for sub in test_list for ele in sub]
    res = list(zip(*temp))
    return str(res)

Prompt: Write a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('defaultdict',)
  IMPORT_NAME collections
  IMPORT_FROM defaultdict
  STORE_NAME defaultdict
  POP_TOP
  LOAD_CONST <code grouping_dictionary>
  MAKE_FUNCTION 0
  STORE_NAME grouping_dictionary
  RETURN_CONST None
END
CODE grouping_dictionary(l)
  RESUME 0
  LOAD_GLOBAL NULL + defaultdict
  LOAD_GLOBAL list
  CALL 1
  STORE_FAST d
  LOAD_FAST l
  GET_ITER
L1:
  FOR_ITER L2
  UNPACK_SEQUENCE 2
  STORE_FAST k
  STORE_FAST v
  LOAD_FAST d
  LOAD_FAST k
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + append
  LOAD_FAST v
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST d
  RETURN_VALUE
END

from collections import defaultdict

def grouping_dictionary(l):
    d = defaultdict(list)
    for k, v in l:
        d[k].append(v)
    return d

Prompt: Write a function to group a sequence of key-value pairs into a dictionary of lists using collections module.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code rectangle_perimeter>
  MAKE_FUNCTION 0
  STORE_NAME rectangle_perimeter
  RETURN_CONST None
END
CODE rectangle_perimeter(l, b)
  RESUME 0
  LOAD_CONST 2
  LOAD_FAST l
  LOAD_FAST b
  BINARY_OP +
  BINARY_OP *
  STORE_FAST perimeter
  LOAD_FAST perimeter
  RETURN_VALUE
END

def rectangle_perimeter(l, b):
    perimeter = 2 * (l + b)
    return perimeter

Prompt: Write a function to find the perimeter of a rectangle.

assert rectangle_perimeter(10,20)==60
assert rectangle_perimeter(10,5)==30
assert rectangle_perimeter(4,2)==12


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code fifth_Power_Sum>
  MAKE_FUNCTION 0
  STORE_NAME fifth_Power_Sum
  RETURN_CONST None
END
CODE fifth_Power_Sum(n)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST sm
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST i
  LOAD_FAST sm
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST i
  BINARY_OP *
  BINARY_OP +
  STORE_FAST sm
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_FAST sm
  RETURN_VALUE
END

def fifth_Power_Sum(n):
    sm = 0
    for i in range(1, n + 1):
        sm = sm + i * i * i * i * i
    return sm

Prompt: Write a python function to find the sum of fifth power of n natural numbers.

assert fifth_Power_Sum(2) == 33
assert fifth_Power_Sum(4) == 1300
assert fifth_Power_Sum(3) == 276


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code first_Digit>
  MAKE_FUNCTION 0
  STORE_NAME first_Digit
  RETURN_CONST None
END
CODE first_Digit(n)
  RESUME 0
  LOAD_CONST 1
  STORE_FAST fact
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L1:
  FOR_ITER L4
  STORE_FAST i
  LOAD_FAST fact
  LOAD_FAST i
  BINARY_OP *
  STORE_FAST fact
  LOAD_FAST fact
  LOAD_CONST 10
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_GLOBAL NULL + int
  LOAD_FAST fact
  LOAD_CONST 10
  BINARY_OP /
  CALL 1
  STORE_FAST fact
  LOAD_FAST fact
  LOAD_CONST 10
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L2
L3:
  JUMP_BACKWARD L1
L4:
  END_FOR
  LOAD_FAST fact
  LOAD_CONST 10
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L6
L5:
  LOAD_GLOBAL NULL + int
  LOAD_FAST fact
  LOAD_CONST 10
  BINARY_OP /
  CALL 1
  STORE_FAST fact
  LOAD_FAST fact
  LOAD_CONST 10
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L6
  JUMP_BACKWARD L5
L6:
  LOAD_GLOBAL NULL + math
  LOAD_ATTR floor
  LOAD_FAST fact
  CALL 1
  RETURN_VALUE
END

import math

def first_Digit(n):
    fact = 1
    for i in range(2, n + 1):
        fact = fact * i
        while fact % 10 == 0:
            fact = int(fact / 10)
    while fact >= 10:
        fact = int(fact / 10)
    return math.floor(fact)

Prompt: Write a python function to find the first digit in factorial of a given number.

assert first_Digit(5) == 1
assert first_Digit(10) == 3
assert first_Digit(7) == 5


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code max_occurrences>
  MAKE_FUNCTION 0
  STORE_NAME max_occurrences
  RETURN_CONST None
END
CODE max_occurrences(list1)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST max_val
  LOAD_FAST list1
  LOAD_CONST 0
  BINARY_SUBSCR
  STORE_FAST result
  LOAD_FAST list1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST list1
  LOAD_ATTR NULL|self + count
  LOAD_FAST i
  CALL 1
  STORE_FAST occu
  LOAD_FAST occu
  LOAD_FAST max_val
  COMPARE_OP >
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST occu
  STORE_FAST max_val
  LOAD_FAST i
  STORE_FAST result
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST result
  RETURN_VALUE
END

def max_occurrences(list1):
    max_val = 0
    result = list1[0]
    for i in list1:
        occu = list1.count(i)
        if occu > max_val:
            max_val = occu
            result = i
    return result

Prompt: Write a function to find the item with maximum occurrences in a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Repeat>
  MAKE_FUNCTION 0
  STORE_NAME Repeat
  RETURN_CONST None
END
CODE Repeat(x)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_FAST x
  CALL 1
  STORE_FAST _size
  BUILD_LIST 0
  STORE_FAST repeated
  LOAD_GLOBAL NULL + range
  LOAD_FAST _size
  CALL 1
  GET_ITER
L1:
  FOR_ITER L6
  STORE_FAST i
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST k
  LOAD_GLOBAL NULL + range
  LOAD_FAST k
  LOAD_FAST _size
  CALL 2
  GET_ITER
L2:
  FOR_ITER L5
  STORE_FAST j
  LOAD_FAST x
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST x
  LOAD_FAST j
  BINARY_SUBSCR
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L3
  JUMP_BACKWARD L2
L3:
  LOAD_FAST x
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST repeated
  CONTAINS_OP 1
  POP_JUMP_IF_TRUE L4
  JUMP_BACKWARD L2
L4:
  LOAD_FAST repeated
  LOAD_ATTR NULL|self + append
  LOAD_FAST x
  LOAD_FAST i
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  JUMP_BACKWARD L2
L5:
  END_FOR
  JUMP_BACKWARD L1
L6:
  END_FOR
  LOAD_FAST repeated
  RETURN_VALUE
END

def Repeat(x):
    _size = len(x)
    repeated = []
    for i in range(_size):
        k = i + 1
        for j in range(k, _size):
            if x[i] == x[j] and x[i] not in repeated:
                repeated.append(x[i])
    return repeated

Prompt: Write a python function to print duplicants from a list of integers.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code find_Points>
  MAKE_FUNCTION 0
  STORE_NAME find_Points
  RETURN_CONST None
END
CODE find_Points(l1, r1, l2, r2)
  RESUME 0
  LOAD_FAST l1
  LOAD_FAST l2
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  LOAD_GLOBAL NULL + min
  LOAD_FAST l1
  LOAD_FAST l2
  CALL 2
  JUMP_FORWARD L2
L1:
  LOAD_CONST -1
L2:
  STORE_FAST x
  LOAD_FAST r1
  LOAD_FAST r2
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L3
  LOAD_GLOBAL NULL + max
  LOAD_FAST r1
  LOAD_FAST r2
  CALL 2
  JUMP_FORWARD L4
L3:
  LOAD_CONST -1
L4:
  STORE_FAST y
  LOAD_FAST x
  LOAD_FAST y
  BUILD_TUPLE 2
  RETURN_VALUE
END

def find_Points(l1, r1, l2, r2):
    x = min(l1, l2) if l1 != l2 else -1
    y = max(r1, r2) if r1 != r2 else -1
    return (x, y)

Prompt: Write a python function to choose points from two ranges such that no point lies in both the ranges.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code max_sum_of_three_consecutive>
  MAKE_FUNCTION 0
  STORE_NAME max_sum_of_three_consecutive
  RETURN_CONST None
END
CODE max_sum_of_three_consecutive(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR k
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST k
  LOAD_CONST 0
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST sum
  STORE_FAST k
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L5
  LOAD_FAST arr
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST sum
  LOAD_CONST 0
  STORE_SUBSCR
L5:
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L6
  LOAD_FAST arr
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_CONST 1
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST sum
  LOAD_CONST 1
  STORE_SUBSCR
L6:
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP >
  POP_JUMP_IF_FALSE L7
  LOAD_GLOBAL NULL + max
  LOAD_FAST sum
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_GLOBAL NULL + max
  LOAD_FAST arr
  LOAD_CONST 1
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_CONST 2
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST arr
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_CONST 2
  BINARY_SUBSCR
  BINARY_OP +
  CALL 2
  CALL 2
  LOAD_FAST sum
  LOAD_CONST 2
  STORE_SUBSCR
L7:
  LOAD_GLOBAL NULL + range
  LOAD_CONST 3
  LOAD_FAST n
  CALL 2
  GET_ITER
L8:
  FOR_ITER L9
  STORE_FAST i
  LOAD_GLOBAL NULL + max
  LOAD_GLOBAL NULL + max
  LOAD_FAST sum
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST sum
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP -
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  BINARY_OP +
  CALL 2
  LOAD_FAST arr
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST arr
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_OP +
  LOAD_FAST sum
  LOAD_FAST i
  LOAD_CONST 3
  BINARY_OP -
  BINARY_SUBSCR
  BINARY_OP +
  CALL 2
  LOAD_FAST sum
  LOAD_FAST i
  STORE_SUBSCR
  JUMP_BACKWARD L8
L9:
  END_FOR
  LOAD_FAST sum
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  RETURN_VALUE
L10:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST k
  RERAISE 0
  EXC try=L1..L4 -> handler=L10 depth=2 lasti=False
END

def max_sum_of_three_consecutive(arr, n):
    sum = [0 for k in range(n)]
    if n >= 1:
        sum[0] = arr[0]
    if n >= 2:
        sum[1] = arr[0] + arr[1]
    if n > 2:
        sum[2] = max(sum[1], max(arr[1] + arr[2], arr[0] + arr[2]))
    for i in range(3, n):
        sum[i] = max(max(sum[i - 1], sum[i - 2] + arr[i]), arr[i] + arr[i - 1] + sum[i - 3])
    return sum[n - 1]

Prompt: Write a function to find the maximum sum that can be formed which has no three consecutive elements present.

assert max_sum_of_three_consecutive([1, 2, 3, 4, 5, 6, 7, 8], 8) == 27


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code average_Even>
  MAKE_FUNCTION 0
  STORE_NAME average_Even
  RETURN_CONST None
END
CODE average_Even(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Invalid Input'
L1:
  LOAD_CONST 0
  STORE_FAST sm
  LOAD_CONST 0
  STORE_FAST count
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L3
L2:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST count
  LOAD_FAST sm
  LOAD_FAST n
  BINARY_OP +
  STORE_FAST sm
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP -
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L2
L3:
  LOAD_FAST sm
  LOAD_FAST count
  BINARY_OP //
  RETURN_VALUE
END

def average_Even(n):
    if n % 2 != 0:
        return 'Invalid Input'
        return -1
    sm = 0
    count = 0
    while n >= 2:
        count = count + 1
        sm = sm + n
        n = n - 2
    return sm // count

Prompt: Write a python function to find the average of even numbers till a given even number.

assert average_Even(2) == 2
assert average_Even(4) == 3
assert average_Even(100) == 51


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code move_last>
  MAKE_FUNCTION 0
  STORE_NAME move_last
  RETURN_CONST None
END
CODE move_last(num_list)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST num_list
  LOAD_ATTR NULL|self + count
  LOAD_FAST num_list
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST num_list
  LOAD_CONST 0
  BINARY_SUBSCR
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST a
  STORE_FAST i
  LOAD_FAST num_list
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L5:
  BUILD_LIST 0
  SWAP 2
L6:
  FOR_ITER L9
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST num_list
  LOAD_CONST 0
  BINARY_SUBSCR
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L8
L7:
  JUMP_BACKWARD L6
L8:
  LOAD_FAST i
  LIST_APPEND 2
  JUMP_BACKWARD L6
L9:
  END_FOR
L10:
  STORE_FAST x
  STORE_FAST i
  LOAD_FAST x
  LOAD_ATTR NULL|self + extend
  LOAD_FAST a
  CALL 1
  POP_TOP
  LOAD_FAST x
  RETURN_VALUE
L11:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
L12:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L11 depth=2 lasti=False
  EXC try=L5..L7 -> handler=L12 depth=2 lasti=False
  EXC try=L8..L10 -> handler=L12 depth=2 lasti=False
END

def move_last(num_list):
    a = [num_list[0] for i in range(num_list.count(num_list[0]))]
    x = [i for i in num_list if i != num_list[0]]
    x.extend(a)
    return x

Prompt: Write a python function to shift first element to the end of given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_char>
  MAKE_FUNCTION 0
  STORE_NAME count_char
  RETURN_CONST None
END
CODE count_char(string, char)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST count
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST string
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST string
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST char
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST count
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST count
  RETURN_VALUE
END

def count_char(string, char):
    count = 0
    for i in range(len(string)):
        if string[i] == char:
            count = count + 1
    return count

Prompt: Write a function to count occurrence of a character in a string.

assert count_char("Python",'o')==1
assert count_char("little",'t')==2
assert count_char("assert",'s')==2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Check_Vow>
  MAKE_FUNCTION 0
  STORE_NAME Check_Vow
  RETURN_CONST None
END
CODE Check_Vow(string, vowels)
  RESUME 0
  LOAD_FAST string
  GET_ITER
  LOAD_FAST_AND_CLEAR each
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L5
  STORE_FAST each
  LOAD_FAST each
  LOAD_FAST vowels
  CONTAINS_OP 0
  POP_JUMP_IF_TRUE L4
L3:
  JUMP_BACKWARD L2
L4:
  LOAD_FAST each
  LIST_APPEND 2
  JUMP_BACKWARD L2
L5:
  END_FOR
L6:
  STORE_FAST final
  STORE_FAST each
  LOAD_GLOBAL NULL + len
  LOAD_FAST final
  CALL 1
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST each
  RERAISE 0
  EXC try=L1..L3 -> handler=L7 depth=2 lasti=False
  EXC try=L4..L6 -> handler=L7 depth=2 lasti=False
END

def Check_Vow(string, vowels):
    final = [each for each in string if each in vowels]
    return len(final)

Prompt: Write a python function to count number of vowels in the string.

assert Check_Vow('corner','AaEeIiOoUu') == 2

assert Check_Vow('valid','AaEeIiOoUu') == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME re
  STORE_NAME re
  LOAD_CONST '^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\\.( \n\t\t\t25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$'
  STORE_NAME regex
  LOAD_CONST <code check_IP>
  MAKE_FUNCTION 0
  STORE_NAME check_IP
  RETURN_CONST None
END
CODE check_IP(Ip)
  RESUME 0
  LOAD_GLOBAL NULL + re
  LOAD_ATTR search
  LOAD_GLOBAL regex
  LOAD_FAST Ip
  CALL 2
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 'Valid IP address'
L1:
  RETURN_CONST 'Invalid IP address'
END

Prompt: Write a function to check whether the given ip address is valid or not using regex.

assert check_IP("192.168.0.1") == 'Valid IP address'

assert check_IP("110.234.52.124") == 'Valid IP address'

assert check_IP("366.1.2.2") == 'Invalid IP address'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code decreasing_trend>
  MAKE_FUNCTION 0
  STORE_NAME decreasing_trend
  RETURN_CONST None
END
CODE decreasing_trend(nums)
  RESUME 0
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST nums
  CALL 1
  LOAD_FAST nums
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST True
L1:
  RETURN_CONST False
END

def decreasing_trend(nums):
    if sorted(nums) == nums:
        return True
    else:
        return False

Prompt: Write a python function to check whether a sequence of numbers has a decreasing trend or not.

assert decreasing_trend([-4,-3,-2,-1]) == True

assert decreasing_trend([1,2,3]) == True

assert decreasing_trend([3,2,1]) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME math
  STORE_NAME math
  LOAD_CONST <code get_Pos_Of_Right_most_Set_Bit>
  MAKE_FUNCTION 0
  STORE_NAME get_Pos_Of_Right_most_Set_Bit
  LOAD_CONST <code set_Right_most_Unset_Bit>
  MAKE_FUNCTION 0
  STORE_NAME set_Right_most_Unset_Bit
  RETURN_CONST None
END
CODE get_Pos_Of_Right_most_Set_Bit(n)
  RESUME 0
  LOAD_GLOBAL NULL + int
  LOAD_GLOBAL NULL + math
  LOAD_ATTR log2
  LOAD_FAST n
  LOAD_FAST n
  UNARY_NEGATIVE
  BINARY_OP &
  CALL 1
  LOAD_CONST 1
  BINARY_OP +
  CALL 1
  RETURN_VALUE
END
CODE set_Right_most_Unset_Bit(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 1
L1:
  LOAD_FAST n
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP &
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST n
  RETURN_VALUE
L2:
  LOAD_GLOBAL NULL + get_Pos_Of_Right_most_Set_Bit
  LOAD_FAST n
  UNARY_INVERT
  CALL 1
  STORE_FAST pos
  LOAD_CONST 1
  LOAD_FAST pos
  LOAD_CONST 1
  BINARY_OP -
  BINARY_OP <<
  LOAD_FAST n
  BINARY_OP |
  RETURN_VALUE
END

import math

def get_Pos_Of_Right_most_Set_Bit(n):
    return int(math.log2(n & -n) + 1)

def set_Right_most_Unset_Bit(n):
    if n == 0:
        return 1
    if n & n + 1 == 0:
        return n
    pos = get_Pos_Of_Right_most_Set_Bit(~n)
    return 1 << pos - 1 | n

Prompt: Write a python function to set the right most unset bit.

assert set_Right_most_Unset_Bit(21) == 23

assert set_Right_most_Unset_Bit(11) == 15

assert set_Right_most_Unset_Bit(15) == 15


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code convert>
  MAKE_FUNCTION 0
  STORE_NAME convert
  RETURN_CONST None
END
CODE convert(list)
  RESUME 0
  LOAD_FAST list
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_GLOBAL NULL + str
  LOAD_FAST i
  CALL 1
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST s
  STORE_FAST i
  LOAD_GLOBAL NULL + int
  LOAD_CONST ''
  LOAD_ATTR NULL|self + join
  LOAD_FAST s
  CALL 1
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=2 lasti=False
END

def convert(list):
    s = [str(i) for i in list]
    res = int(''.join(s))
    return res

Prompt: Write a python function to convert a list of multiple integers into a single integer.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('OrderedDict',)
  IMPORT_NAME collections
  IMPORT_FROM OrderedDict
  STORE_NAME OrderedDict
  POP_TOP
  LOAD_CONST <code remove_duplicate>
  MAKE_FUNCTION 0
  STORE_NAME remove_duplicate
  RETURN_CONST None
END
CODE remove_duplicate(string)
  RESUME 0
  LOAD_CONST ' '
  LOAD_ATTR NULL|self + join
  LOAD_GLOBAL NULL + OrderedDict
  LOAD_CONST <code remove_duplicate.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_FAST string
  LOAD_ATTR NULL|self + split
  CALL 0
  GET_ITER
  CALL 0
  CALL 1
  LOAD_ATTR NULL|self + keys
  CALL 0
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END
CODE remove_duplicate.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  STORE_FAST w
  LOAD_FAST w
  LOAD_FAST w
  BUILD_TUPLE 2
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

from collections import OrderedDict

def remove_duplicate(string):
    result = ' '.join(OrderedDict(((w, w) for w in string.split())).keys())
    return result

Prompt: Write a function to remove duplicate words from a given string using collections module.

assert remove_duplicate("Python Exercises Practice Solution Exercises")==("Python Exercises Practice Solution")

assert remove_duplicate("Python Exercises Practice Solution Python")==("Python Exercises Practice Solution")

assert remove_duplicate("Python Exercises Practice Solution Practice")==("Python Exercises Practice Solution")


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code remove_spaces>
  MAKE_FUNCTION 0
  STORE_NAME remove_spaces
  RETURN_CONST None
END
CODE remove_spaces(str1)
  RESUME 0
  LOAD_FAST str1
  LOAD_ATTR NULL|self + replace
  LOAD_CONST ' '
  LOAD_CONST ''
  CALL 2
  STORE_FAST str1
  LOAD_FAST str1
  RETURN_VALUE
END

def remove_spaces(str1):
    str1 = str1.replace(' ', '')
    return str1

Prompt: Write a python function to remove spaces from a given string.

assert remove_spaces("a b c") == "abc"
assert remove_spaces("1 2 3") == "123"
assert remove_spaces(" b c") == "bc"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code access_key>
  MAKE_FUNCTION 0
  STORE_NAME access_key
  RETURN_CONST None
END
CODE access_key(ditionary, key)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_FAST ditionary
  CALL 1
  LOAD_FAST key
  BINARY_SUBSCR
  RETURN_VALUE
END

def access_key(ditionary, key):
    return list(ditionary)[key]

Prompt: Write a function to access dictionary key’s element by index.

assert access_key({'physics': 80, 'math': 90, 'chemistry': 86},0)== 'physics'


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code smallest_Divisor>
  MAKE_FUNCTION 0
  STORE_NAME smallest_Divisor
  RETURN_CONST None
END
CODE smallest_Divisor(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 2
L1:
  LOAD_CONST 3
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
L2:
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST i
  RETURN_VALUE
L3:
  LOAD_FAST i
  LOAD_CONST 2
  BINARY_OP +=
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L2
L4:
  LOAD_FAST n
  RETURN_VALUE
END

def smallest_Divisor(n):
    if n % 2 == 0:
        return 2
    i = 3
    while i * i <= n:
        if n % i == 0:
            return i
        i += 2
    return n

Prompt: Write a python function to find the smallest prime divisor of a number.

assert smallest_Divisor(10) == 2
assert smallest_Divisor(25) == 5
assert smallest_Divisor(31) == 31


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code mul_list>
  MAKE_FUNCTION 0
  STORE_NAME mul_list
  RETURN_CONST None
END
CODE mul_list(nums1, nums2)
  RESUME 0
  LOAD_GLOBAL NULL + map
  LOAD_CONST <code mul_list.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST nums1
  LOAD_FAST nums2
  CALL 3
  STORE_FAST result
  LOAD_GLOBAL NULL + list
  LOAD_FAST result
  CALL 1
  RETURN_VALUE
END
CODE mul_list.<locals>.<lambda>(x, y)
  RESUME 0
  LOAD_FAST x
  LOAD_FAST y
  BINARY_OP *
  RETURN_VALUE
END

def mul_list(nums1, nums2):
    result = map(lambda x, y: x * y, nums1, nums2)
    return list(result)

Prompt: Write a function to multiply two lists using map and lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_Square>
  MAKE_FUNCTION 0
  STORE_NAME sum_Square
  RETURN_CONST None
END
CODE sum_Square(n)
  RESUME 0
  LOAD_CONST 1
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
L1:
  LOAD_CONST 1
  STORE_FAST j
  LOAD_FAST j
  LOAD_FAST j
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
L2:
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST j
  LOAD_FAST j
  BINARY_OP *
  BINARY_OP +
  LOAD_FAST n
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  RETURN_CONST True
L3:
  LOAD_FAST j
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST j
  LOAD_FAST j
  LOAD_FAST j
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L2
L4:
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L1
L5:
  RETURN_CONST False
END

def sum_Square(n):
    i = 1
    while i * i <= n:
        j = 1
        while j * j <= n:
            if i * i + j * j == n:
                return True
            j = j + 1
        i = i + 1
    return False

Prompt: Write a python function to check whether the given number can be represented by sum of two squares or not.

assert sum_Square(25) == True
assert sum_Square(24) == False
assert sum_Square(17) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_Char>
  MAKE_FUNCTION 0
  STORE_NAME count_Char
  RETURN_CONST None
END
CODE count_Char(str, x)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST count
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST str
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST str
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST x
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_CONST 10
  STORE_FAST n
  LOAD_FAST n
  LOAD_GLOBAL NULL + len
  LOAD_FAST str
  CALL 1
  BINARY_OP //
  STORE_FAST repititions
  LOAD_FAST count
  LOAD_FAST repititions
  BINARY_OP *
  STORE_FAST count
  LOAD_FAST n
  LOAD_GLOBAL NULL + len
  LOAD_FAST str
  CALL 1
  BINARY_OP %
  STORE_FAST l
  LOAD_GLOBAL NULL + range
  LOAD_FAST l
  CALL 1
  GET_ITER
L4:
  FOR_ITER L6
  STORE_FAST i
  LOAD_FAST str
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST x
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L5
  JUMP_BACKWARD L4
L5:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
  JUMP_BACKWARD L4
L6:
  END_FOR
  LOAD_FAST count
  RETURN_VALUE
END

def count_Char(str, x):
    count = 0
    for i in range(len(str)):
        if str[i] == x:
            count += 1
    n = 10
    repititions = n // len(str)
    count = count * repititions
    l = n % len(str)
    for i in range(l):
        if str[i] == x:
            count += 1
    return count

Prompt: Write a python function to count occurences of a character in a repeated string.

assert count_Char("abcac",'a') == 4
assert count_Char("abca",'c') == 2
assert count_Char("aba",'a') == 7


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sum_Of_Primes>
  MAKE_FUNCTION 0
  STORE_NAME sum_Of_Primes
  RETURN_CONST None
END
CODE sum_Of_Primes(n)
  RESUME 0
  LOAD_CONST True
  BUILD_LIST 1
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  BINARY_OP *
  STORE_FAST prime
  LOAD_CONST 2
  STORE_FAST p
  LOAD_FAST p
  LOAD_FAST p
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
L1:
  LOAD_FAST prime
  LOAD_FAST p
  BINARY_SUBSCR
  LOAD_CONST True
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  LOAD_FAST p
  LOAD_CONST 2
  BINARY_OP *
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L3
L2:
  LOAD_CONST False
  LOAD_FAST prime
  LOAD_FAST i
  STORE_SUBSCR
  LOAD_FAST i
  LOAD_FAST p
  BINARY_OP +=
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L2
L3:
  LOAD_FAST p
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST p
  LOAD_FAST p
  LOAD_FAST p
  BINARY_OP *
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L1
L4:
  LOAD_CONST 0
  STORE_FAST sum
  LOAD_GLOBAL NULL + range
  LOAD_CONST 2
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L5:
  FOR_ITER L7
  STORE_FAST i
  LOAD_FAST prime
  LOAD_FAST i
  BINARY_SUBSCR
  POP_JUMP_IF_TRUE L6
  JUMP_BACKWARD L5
L6:
  LOAD_FAST sum
  LOAD_FAST i
  BINARY_OP +=
  STORE_FAST sum
  JUMP_BACKWARD L5
L7:
  END_FOR
  LOAD_FAST sum
  RETURN_VALUE
END

def sum_Of_Primes(n):
    prime = [True] * (n + 1)
    p = 2
    while p * p <= n:
        if prime[p] == True:
            i = p * 2
            while i <= n:
                prime[i] = False
                i += p
        p += 1
    sum = 0
    for i in range(2, n + 1):
        if prime[i]:
            sum += i
    return sum

Prompt: Write a python function to find sum of prime numbers between 1 to n.

assert sum_Of_Primes(10) == 17
assert sum_Of_Primes(20) == 77
assert sum_Of_Primes(5) == 10


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('defaultdict',)
  IMPORT_NAME collections
  IMPORT_FROM defaultdict
  STORE_NAME defaultdict
  POP_TOP
  LOAD_CONST <code freq_element>
  MAKE_FUNCTION 0
  STORE_NAME freq_element
  RETURN_CONST None
END
CODE freq_element(test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + defaultdict
  LOAD_GLOBAL int
  CALL 1
  STORE_FAST res
  LOAD_FAST test_tup
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST ele
  LOAD_FAST res
  LOAD_FAST ele
  COPY 2
  COPY 2
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +=
  SWAP 3
  SWAP 2
  STORE_SUBSCR
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + str
  LOAD_GLOBAL NULL + dict
  LOAD_FAST res
  CALL 1
  CALL 1
  RETURN_VALUE
END

from collections import defaultdict

def freq_element(test_tup):
    res = defaultdict(int)
    for ele in test_tup:
        res[ele] += 1
    return str(dict(res))

Prompt: Write a function to find the frequency of each element in the given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME cmath
  STORE_NAME cmath
  LOAD_CONST <code len_complex>
  MAKE_FUNCTION 0
  STORE_NAME len_complex
  RETURN_CONST None
END
CODE len_complex(a, b)
  RESUME 0
  LOAD_GLOBAL NULL + complex
  LOAD_FAST a
  LOAD_FAST b
  CALL 2
  STORE_FAST cn
  LOAD_GLOBAL NULL + abs
  LOAD_FAST cn
  CALL 1
  STORE_FAST length
  LOAD_FAST length
  RETURN_VALUE
END

import cmath

def len_complex(a, b):
    cn = complex(a, b)
    length = abs(cn)
    return length

Prompt: Write a function to get the length of a complex number.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code min_jumps>
  MAKE_FUNCTION 0
  STORE_NAME min_jumps
  RETURN_CONST None
END
CODE min_jumps(arr, n)
  RESUME 0
  LOAD_GLOBAL NULL + range
  LOAD_FAST n
  CALL 1
  GET_ITER
  LOAD_FAST_AND_CLEAR i
  SWAP 2
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_CONST 0
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST jumps
  STORE_FAST i
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_TRUE L5
  LOAD_FAST arr
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L6
L5:
  LOAD_GLOBAL NULL + float
  LOAD_CONST 'inf'
  CALL 1
  RETURN_VALUE
L6:
  LOAD_CONST 0
  LOAD_FAST jumps
  LOAD_CONST 0
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST n
  CALL 2
  GET_ITER
L7:
  FOR_ITER L12
  STORE_FAST i
  LOAD_GLOBAL NULL + float
  LOAD_CONST 'inf'
  CALL 1
  LOAD_FAST jumps
  LOAD_FAST i
  STORE_SUBSCR
  LOAD_GLOBAL NULL + range
  LOAD_FAST i
  CALL 1
  GET_ITER
L8:
  FOR_ITER L11
  STORE_FAST j
  LOAD_FAST i
  LOAD_FAST j
  LOAD_FAST arr
  LOAD_FAST j
  BINARY_SUBSCR
  BINARY_OP +
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L9
  JUMP_BACKWARD L8
L9:
  LOAD_FAST jumps
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_GLOBAL NULL + float
  LOAD_CONST 'inf'
  CALL 1
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L10
  JUMP_BACKWARD L8
L10:
  LOAD_GLOBAL NULL + min
  LOAD_FAST jumps
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST jumps
  LOAD_FAST j
  BINARY_SUBSCR
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  LOAD_FAST jumps
  LOAD_FAST i
  STORE_SUBSCR
  POP_TOP
  JUMP_BACKWARD L7
L11:
  END_FOR
  JUMP_BACKWARD L7
L12:
  END_FOR
  LOAD_FAST jumps
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  BINARY_SUBSCR
  RETURN_VALUE
L13:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST i
  RERAISE 0
  EXC try=L1..L4 -> handler=L13 depth=2 lasti=False
END

def min_jumps(arr, n):
    jumps = [0 for i in range(n)]
    if n == 0 or arr[0] == 0:
        return float('inf')
    jumps[0] = 0
    for i in range(1, n):
        jumps[i] = float('inf')
        for j in range(i):
            if i <= j + arr[j] and jumps[j] != float('inf'):
                jumps[i] = min(jumps[i], jumps[j] + 1)
                break
    return jumps[n - 1]

Prompt: ## write a function to find the minimum number of jumps to reach the end of the array for the given array of integers where each element represents the max number of steps that can be made forward from that element. > indented block > indented block


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code mul_consecutive_nums>
  MAKE_FUNCTION 0
  STORE_NAME mul_consecutive_nums
  RETURN_CONST None
END
CODE mul_consecutive_nums(nums)
  RESUME 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST nums
  LOAD_CONST None
  LOAD_CONST -1
  BINARY_SLICE
  LOAD_FAST nums
  LOAD_CONST 1
  LOAD_CONST None
  BINARY_SLICE
  CALL 2
  GET_ITER
  LOAD_FAST_AND_CLEAR a
  LOAD_FAST_AND_CLEAR b
  SWAP 3
L1:
  BUILD_LIST 0
  SWAP 2
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST a
  STORE_FAST b
  LOAD_FAST b
  LOAD_FAST a
  BINARY_OP *
  LIST_APPEND 2
  JUMP_BACKWARD L2
L3:
  END_FOR
L4:
  STORE_FAST result
  STORE_FAST a
  STORE_FAST b
  LOAD_FAST result
  RETURN_VALUE
L5:
  SWAP 2
  POP_TOP
  SWAP 3
  STORE_FAST b
  STORE_FAST a
  RERAISE 0
  EXC try=L1..L4 -> handler=L5 depth=3 lasti=False
END

def mul_consecutive_nums(nums):
    result = [b * a for a, b in zip(nums[:-1], nums[1:])]
    return result

Prompt: Write a function to multiply consecutive numbers of a given list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('groupby',)
  IMPORT_NAME itertools
  IMPORT_FROM groupby
  STORE_NAME groupby
  POP_TOP
  LOAD_CONST <code group_element>
  MAKE_FUNCTION 0
  STORE_NAME group_element
  RETURN_CONST None
END
CODE group_element(test_list)
  RESUME 0
  LOAD_GLOBAL NULL + dict
  CALL 0
  STORE_FAST res
  LOAD_GLOBAL NULL + groupby
  LOAD_GLOBAL NULL + sorted
  LOAD_FAST test_list
  LOAD_CONST <code group_element.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  LOAD_CONST <code group_element.<locals>.<lambda>>
  MAKE_FUNCTION 0
  KW_NAMES ('key',)
  CALL 2
  GET_ITER
L1:
  FOR_ITER L6
  UNPACK_SEQUENCE 2
  STORE_FAST key
  STORE_FAST val
  LOAD_FAST val
  GET_ITER
  LOAD_FAST_AND_CLEAR ele
  SWAP 2
L2:
  BUILD_LIST 0
  SWAP 2
L3:
  FOR_ITER L4
  STORE_FAST ele
  LOAD_FAST ele
  LOAD_CONST 0
  BINARY_SUBSCR
  LIST_APPEND 2
  JUMP_BACKWARD L3
L4:
  END_FOR
L5:
  SWAP 2
  STORE_FAST ele
  LOAD_FAST res
  LOAD_FAST key
  STORE_SUBSCR
  JUMP_BACKWARD L1
L6:
  END_FOR
  LOAD_FAST res
  RETURN_VALUE
L7:
  SWAP 2
  POP_TOP
  SWAP 2
  STORE_FAST ele
  RERAISE 0
  EXC try=L2..L5 -> handler=L7 depth=3 lasti=False
END
CODE group_element.<locals>.<lambda>(ele)
  RESUME 0
  LOAD_FAST ele
  LOAD_CONST 1
  BINARY_SUBSCR
  RETURN_VALUE
END
CODE group_element.<locals>.<lambda>(ele)
  RESUME 0
  LOAD_FAST ele
  LOAD_CONST 1
  BINARY_SUBSCR
  RETURN_VALUE
END

from itertools import groupby

def group_element(test_list):
    res = dict()
    for key, val in groupby(sorted(test_list, key=lambda ele: ele[1]), key=lambda ele: ele[1]):
        res[key] = [ele[0] for ele in val]
    return res

Prompt: Write a function to group the 1st elements on the basis of 2nd elements in the given tuple list.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code last_Two_Digits>
  MAKE_FUNCTION 0
  STORE_NAME last_Two_Digits
  RETURN_CONST None
END
CODE last_Two_Digits(N)
  RESUME 0
  LOAD_FAST N
  LOAD_CONST 10
  COMPARE_OP >=
  POP_JUMP_IF_FALSE L1
  RETURN_CONST None
L1:
  LOAD_CONST 1
  STORE_FAST fac
  LOAD_GLOBAL NULL + range
  LOAD_CONST 1
  LOAD_FAST N
  LOAD_CONST 1
  BINARY_OP +
  CALL 2
  GET_ITER
L2:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST fac
  LOAD_FAST i
  BINARY_OP *
  LOAD_CONST 100
  BINARY_OP %
  STORE_FAST fac
  JUMP_BACKWARD L2
L3:
  END_FOR
  LOAD_FAST fac
  RETURN_VALUE
END

def last_Two_Digits(N):
    if N >= 10:
        return
    fac = 1
    for i in range(1, N + 1):
        fac = fac * i % 100
    return fac

Prompt: Write a python function to find the last two digits in factorial of a given number.

assert last_Two_Digits(7) == 40
assert last_Two_Digits(5) == 20
assert last_Two_Digits(2) == 2


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_greater>
  MAKE_FUNCTION 0
  STORE_NAME check_greater
  RETURN_CONST None
END
CODE check_greater(test_tup1, test_tup2)
  RESUME 0
  LOAD_GLOBAL NULL + all
  LOAD_CONST <code check_greater.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + zip
  LOAD_FAST test_tup1
  LOAD_FAST test_tup2
  CALL 2
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END
CODE check_greater.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST x
  STORE_FAST y
  LOAD_FAST x
  LOAD_FAST y
  COMPARE_OP <
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

def check_greater(test_tup1, test_tup2):
    res = all((x < y for x, y in zip(test_tup1, test_tup2)))
    return res

Prompt: Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.

assert check_greater((1, 2, 3), (2, 1, 4)) == False

assert check_greater((4, 5, 6), (5, 6, 7)) == True


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code zip_list>
  MAKE_FUNCTION 0
  STORE_NAME zip_list
  RETURN_CONST None
END
CODE zip_list(list1, list2)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + map
  LOAD_GLOBAL list
  LOAD_ATTR __add__
  LOAD_FAST list1
  LOAD_FAST list2
  CALL 3
  CALL 1
  STORE_FAST result
  LOAD_FAST result
  RETURN_VALUE
END

def zip_list(list1, list2):
    result = list(map(list.__add__, list1, list2))
    return result

Prompt: Write a function to zip two given lists of lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_even>
  MAKE_FUNCTION 0
  STORE_NAME count_even
  RETURN_CONST None
END
CODE count_even(array_nums)
  RESUME 0
  LOAD_GLOBAL NULL + len
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + filter
  LOAD_CONST <code count_even.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST array_nums
  CALL 2
  CALL 1
  CALL 1
  STORE_FAST count_even
  LOAD_FAST count_even
  RETURN_VALUE
END
CODE count_even.<locals>.<lambda>(x)
  RESUME 0
  LOAD_FAST x
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  RETURN_VALUE
END

def count_even(array_nums):
    count_even = len(list(filter(lambda x: x % 2 == 0, array_nums)))
    return count_even

Prompt: Write a function to find number of even elements in the given list using lambda function.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code min_Swaps>
  MAKE_FUNCTION 0
  STORE_NAME min_Swaps
  RETURN_CONST None
END
CODE min_Swaps(str1, str2)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST count
  LOAD_GLOBAL NULL + range
  LOAD_GLOBAL NULL + len
  LOAD_FAST str1
  CALL 1
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  STORE_FAST i
  LOAD_FAST str1
  LOAD_FAST i
  BINARY_SUBSCR
  LOAD_FAST str2
  LOAD_FAST i
  BINARY_SUBSCR
  COMPARE_OP !=
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
  JUMP_BACKWARD L1
L3:
  END_FOR
  LOAD_FAST count
  LOAD_CONST 2
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L4
  LOAD_FAST count
  LOAD_CONST 2
  BINARY_OP //
  RETURN_VALUE
L4:
  RETURN_CONST 'Not Possible'
END

def min_Swaps(str1, str2):
    count = 0
    for i in range(len(str1)):
        if str1[i] != str2[i]:
            count += 1
    if count % 2 == 0:
        return count // 2
    else:
        return 'Not Possible'

Prompt: Write a python function to find the minimum number of swaps required to convert one binary string to another.

assert min_Swaps("1111","0100") == "Not Possible"


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_range_in_list>
  MAKE_FUNCTION 0
  STORE_NAME count_range_in_list
  RETURN_CONST None
END
CODE count_range_in_list(li, min, max)
  RESUME 0
  LOAD_CONST 0
  STORE_FAST ctr
  LOAD_FAST li
  GET_ITER
L1:
  FOR_ITER L5
  STORE_FAST x
  LOAD_FAST min
  LOAD_FAST x
  SWAP 2
  COPY 2
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L3
  LOAD_FAST max
  COMPARE_OP <=
  POP_JUMP_IF_TRUE L2
  JUMP_BACKWARD L1
L2:
  JUMP_FORWARD L4
L3:
  POP_TOP
  JUMP_BACKWARD L1
L4:
  LOAD_FAST ctr
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST ctr
  JUMP_BACKWARD L1
L5:
  END_FOR
  LOAD_FAST ctr
  RETURN_VALUE
END

def count_range_in_list(li, min, max):
    ctr = 0
    for x in li:
        if min <= x <= max:
            ctr += 1
    return ctr

Prompt: Write a function to count the number of elements in a list which are within a specific range.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code equilibrium_index>
  MAKE_FUNCTION 0
  STORE_NAME equilibrium_index
  RETURN_CONST None
END
CODE equilibrium_index(arr)
  RESUME 0
  LOAD_GLOBAL NULL + sum
  LOAD_FAST arr
  CALL 1
  STORE_FAST total_sum
  LOAD_CONST 0
  STORE_FAST left_sum
  LOAD_GLOBAL NULL + enumerate
  LOAD_FAST arr
  CALL 1
  GET_ITER
L1:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST i
  STORE_FAST num
  LOAD_FAST total_sum
  LOAD_FAST num
  BINARY_OP -=
  STORE_FAST total_sum
  LOAD_FAST left_sum
  LOAD_FAST total_sum
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L2
  LOAD_FAST i
  SWAP 2
  POP_TOP
  RETURN_VALUE
L2:
  LOAD_FAST left_sum
  LOAD_FAST num
  BINARY_OP +=
  STORE_FAST left_sum
  JUMP_BACKWARD L1
L3:
  END_FOR
  RETURN_CONST -1
END

def equilibrium_index(arr):
    total_sum = sum(arr)
    left_sum = 0
    for i, num in enumerate(arr):
        total_sum -= num
        if left_sum == total_sum:
            return i
        left_sum += num
    return -1

Prompt: Write a function to find the equilibrium index of the given array.

assert equilibrium_index([1, 2, 3, 4, 1, 2, 3]) == 3

assert equilibrium_index([1, 2, 3]) == -1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code harmonic_sum>
  MAKE_FUNCTION 0
  STORE_NAME harmonic_sum
  RETURN_CONST None
END
CODE harmonic_sum(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 2
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  RETURN_CONST 1
L1:
  LOAD_CONST 1
  LOAD_FAST n
  BINARY_OP /
  LOAD_GLOBAL NULL + harmonic_sum
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP -
  CALL 1
  BINARY_OP +
  RETURN_VALUE
END

def harmonic_sum(n):
    if n < 2:
        return 1
    else:
        return 1 / n + harmonic_sum(n - 1)

Prompt: Write a function to calculate the harmonic sum of n-1.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code sort_sublists>
  MAKE_FUNCTION 0
  STORE_NAME sort_sublists
  RETURN_CONST None
END
CODE sort_sublists(list1)
  RESUME 0
  LOAD_FAST list1
  LOAD_ATTR NULL|self + sort
  CALL 0
  POP_TOP
  LOAD_FAST list1
  LOAD_ATTR NULL|self + sort
  LOAD_GLOBAL len
  KW_NAMES ('key',)
  CALL 1
  POP_TOP
  LOAD_FAST list1
  RETURN_VALUE
END

def sort_sublists(list1):
    list1.sort()
    list1.sort(key=len)
    return list1

Prompt: Write a function to sort a list of lists by length and value.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_Set_Bits>
  MAKE_FUNCTION 0
  STORE_NAME count_Set_Bits
  RETURN_CONST None
END
CODE count_Set_Bits(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST n
  LOAD_CONST 2
  STORE_FAST powerOf2
  LOAD_FAST n
  LOAD_CONST 2
  BINARY_OP //
  STORE_FAST cnt
  LOAD_FAST powerOf2
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
L1:
  LOAD_FAST n
  LOAD_FAST powerOf2
  BINARY_OP //
  STORE_FAST totalPairs
  LOAD_FAST cnt
  LOAD_FAST totalPairs
  LOAD_CONST 2
  BINARY_OP //
  LOAD_FAST powerOf2
  BINARY_OP *
  BINARY_OP +=
  STORE_FAST cnt
  LOAD_FAST totalPairs
  LOAD_CONST 1
  BINARY_OP &
  POP_JUMP_IF_FALSE L2
  LOAD_FAST cnt
  LOAD_FAST n
  LOAD_FAST powerOf2
  BINARY_OP %
  BINARY_OP +=
  STORE_FAST cnt
  JUMP_FORWARD L3
L2:
  LOAD_FAST cnt
  LOAD_CONST 0
  BINARY_OP +=
  STORE_FAST cnt
L3:
  LOAD_FAST powerOf2
  LOAD_CONST 1
  BINARY_OP <<=
  STORE_FAST powerOf2
  LOAD_FAST powerOf2
  LOAD_FAST n
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L1
L4:
  LOAD_FAST cnt
  RETURN_VALUE
END

def count_Set_Bits(n):
    n += 1
    powerOf2 = 2
    cnt = n // 2
    while powerOf2 <= n:
        totalPairs = n // powerOf2
        cnt += totalPairs // 2 * powerOf2
        if totalPairs & 1:
            cnt += n % powerOf2
        else:
            cnt += 0
        powerOf2 <<= 1
    return cnt

Prompt: Write a python function to count the total set bits from 1 to n.

assert count_Set_Bits(16) == 33
assert count_Set_Bits(2) == 2
assert count_Set_Bits(14) == 28


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code Convert>
  MAKE_FUNCTION 0
  STORE_NAME Convert
  RETURN_CONST None
END
CODE Convert(string)
  RESUME 0
  LOAD_GLOBAL NULL + list
  LOAD_FAST string
  LOAD_ATTR NULL|self + split
  LOAD_CONST ' '
  CALL 1
  CALL 1
  STORE_FAST li
  LOAD_FAST li
  RETURN_VALUE
END

def Convert(string):
    li = list(string.split(' '))
    return li

Prompt: Write a python function to convert a string to a list.

assert Convert('python program') == ['python','program']

assert Convert('Data Analysis') ==['Data','Analysis']

assert Convert('Hadoop Training') == ['Hadoop','Training']


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST ('defaultdict',)
  IMPORT_NAME collections
  IMPORT_FROM defaultdict
  STORE_NAME defaultdict
  POP_TOP
  LOAD_CONST <code get_unique>
  MAKE_FUNCTION 0
  STORE_NAME get_unique
  RETURN_CONST None
END
CODE get_unique(test_list)
  RESUME 0
  LOAD_GLOBAL NULL + defaultdict
  LOAD_GLOBAL list
  CALL 1
  STORE_FAST res
  LOAD_FAST test_list
  GET_ITER
L1:
  FOR_ITER L2
  STORE_FAST sub
  LOAD_FAST res
  LOAD_FAST sub
  LOAD_CONST 1
  BINARY_SUBSCR
  BINARY_SUBSCR
  LOAD_ATTR NULL|self + append
  LOAD_FAST sub
  LOAD_CONST 0
  BINARY_SUBSCR
  CALL 1
  POP_TOP
  JUMP_BACKWARD L1
L2:
  END_FOR
  LOAD_GLOBAL NULL + dict
  LOAD_FAST res
  CALL 1
  STORE_FAST res
  LOAD_GLOBAL NULL + dict
  CALL 0
  STORE_FAST res_dict
  LOAD_FAST res
  GET_ITER
L3:
  FOR_ITER L4
  STORE_FAST key
  LOAD_GLOBAL NULL + len
  LOAD_GLOBAL NULL + list
  LOAD_GLOBAL NULL + set
  LOAD_FAST res
  LOAD_FAST key
  BINARY_SUBSCR
  CALL 1
  CALL 1
  CALL 1
  LOAD_FAST res_dict
  LOAD_FAST key
  STORE_SUBSCR
  JUMP_BACKWARD L3
L4:
  END_FOR
  LOAD_GLOBAL NULL + str
  LOAD_FAST res_dict
  CALL 1
  RETURN_VALUE
END

from collections import defaultdict

def get_unique(test_list):
    res = defaultdict(list)
    for sub in test_list:
        res[sub[1]].append(sub[0])
    res = dict(res)
    res_dict = dict()
    for key in res:
        res_dict[key] = len(list(set(res[key])))
    return str(res_dict)

Prompt: Write a function to count unique keys for each value present in the tuple.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code front_and_rear>
  MAKE_FUNCTION 0
  STORE_NAME front_and_rear
  RETURN_CONST None
END
CODE front_and_rear(test_tup)
  RESUME 0
  LOAD_FAST test_tup
  LOAD_CONST 0
  BINARY_SUBSCR
  LOAD_FAST test_tup
  LOAD_CONST -1
  BINARY_SUBSCR
  BUILD_TUPLE 2
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END

def front_and_rear(test_tup):
    res = (test_tup[0], test_tup[-1])
    return res

Prompt: Write a function to access the initial and last data of the given tuple record.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code product_Equal>
  MAKE_FUNCTION 0
  STORE_NAME product_Equal
  RETURN_CONST None
END
CODE product_Equal(n)
  RESUME 0
  LOAD_FAST n
  LOAD_CONST 10
  COMPARE_OP <
  POP_JUMP_IF_FALSE L1
  RETURN_CONST False
L1:
  LOAD_CONST 1
  STORE_FAST prodOdd
  LOAD_CONST 1
  STORE_FAST prodEven
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L4
L2:
  LOAD_FAST n
  LOAD_CONST 10
  BINARY_OP %
  STORE_FAST digit
  LOAD_FAST prodOdd
  LOAD_FAST digit
  BINARY_OP *=
  STORE_FAST prodOdd
  LOAD_FAST n
  LOAD_CONST 10
  BINARY_OP //
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  JUMP_FORWARD L4
L3:
  LOAD_FAST n
  LOAD_CONST 10
  BINARY_OP %
  STORE_FAST digit
  LOAD_FAST prodEven
  LOAD_FAST digit
  BINARY_OP *=
  STORE_FAST prodEven
  LOAD_FAST n
  LOAD_CONST 10
  BINARY_OP //
  STORE_FAST n
  LOAD_FAST n
  LOAD_CONST 0
  COMPARE_OP >
  POP_JUMP_IF_FALSE L4
  JUMP_BACKWARD L2
L4:
  LOAD_FAST prodOdd
  LOAD_FAST prodEven
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L5
  RETURN_CONST True
L5:
  RETURN_CONST False
END

def product_Equal(n):
    if n < 10:
        return False
    prodOdd = 1
    prodEven = 1
    while n > 0:
        digit = n % 10
        prodOdd *= digit
        n = n // 10
        if n == 0:
            break
        digit = n % 10
        prodEven *= digit
        n = n // 10
    if prodOdd == prodEven:
        return True
    return False

Prompt: Write a python function to check whether the product of digits of a number at even and odd places is equal or not.

assert product_Equal(2841) == True
assert product_Equal(1234) == False
assert product_Equal(1212) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST 0
  LOAD_CONST None
  IMPORT_NAME itertools
  STORE_NAME itertools
  LOAD_CONST <code remove_duplicate>
  MAKE_FUNCTION 0
  STORE_NAME remove_duplicate
  RETURN_CONST None
END
CODE remove_duplicate(list1)
  RESUME 0
  LOAD_GLOBAL list
  LOAD_ATTR NULL|self + sort
  LOAD_FAST list1
  CALL 1
  POP_TOP
  LOAD_GLOBAL NULL + list
  LOAD_CONST <code remove_duplicate.<locals>.<genexpr>>
  MAKE_FUNCTION 0
  LOAD_GLOBAL NULL + itertools
  LOAD_ATTR groupby
  LOAD_FAST list1
  CALL 1
  GET_ITER
  CALL 0
  CALL 1
  STORE_FAST remove_duplicate
  LOAD_FAST remove_duplicate
  RETURN_VALUE
END
CODE remove_duplicate.<locals>.<genexpr>(.0)
  RETURN_GENERATOR
  POP_TOP
L1:
  RESUME 0
  LOAD_FAST .0
L2:
  FOR_ITER L3
  UNPACK_SEQUENCE 2
  STORE_FAST list1
  STORE_FAST _
  LOAD_FAST list1
  YIELD_VALUE 1
  RESUME 1
  POP_TOP
  JUMP_BACKWARD L2
L3:
  END_FOR
  RETURN_CONST None
L4:
  CALL_INTRINSIC_1 INTRINSIC_STOPITERATION_ERROR
  RERAISE 1
  EXC try=L1..L4 -> handler=L4 depth=0 lasti=True
END

import itertools

def remove_duplicate(list1):
    list.sort(list1)
    remove_duplicate = list((list1 for list1, _ in itertools.groupby(list1)))
    return remove_duplicate

Prompt: Write a function to remove duplicates from a list of lists.


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code check_valid>
  MAKE_FUNCTION 0
  STORE_NAME check_valid
  RETURN_CONST None
END
CODE check_valid(test_tup)
  RESUME 0
  LOAD_GLOBAL NULL + any
  LOAD_GLOBAL NULL + map
  LOAD_CONST <code check_valid.<locals>.<lambda>>
  MAKE_FUNCTION 0
  LOAD_FAST test_tup
  CALL 2
  CALL 1
  UNARY_NOT
  STORE_FAST res
  LOAD_FAST res
  RETURN_VALUE
END
CODE check_valid.<locals>.<lambda>(ele)
  RESUME 0
  LOAD_FAST ele
  UNARY_NOT
  RETURN_VALUE
END

def check_valid(test_tup):
    res = not any(map(lambda ele: not ele, test_tup))
    return res

Prompt: Write a function to check if the given tuple contains all valid values or not.

assert check_valid((True, True, True, True) ) == True

assert check_valid((True, False, True, True) ) == False


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code count_Fac>
  MAKE_FUNCTION 0
  STORE_NAME count_Fac
  RETURN_CONST None
END
CODE count_Fac(n)
  RESUME 0
  LOAD_FAST n
  STORE_FAST m
  LOAD_CONST 0
  STORE_FAST count
  LOAD_CONST 2
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST m
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L6
L1:
  LOAD_CONST 0
  STORE_FAST total
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
L2:
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP /=
  STORE_FAST n
  LOAD_FAST total
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST total
  LOAD_FAST n
  LOAD_FAST i
  BINARY_OP %
  LOAD_CONST 0
  COMPARE_OP ==
  POP_JUMP_IF_FALSE L3
  JUMP_BACKWARD L2
L3:
  LOAD_CONST 0
  STORE_FAST temp
  LOAD_CONST 1
  STORE_FAST j
  LOAD_FAST temp
  LOAD_FAST j
  BINARY_OP +
  LOAD_FAST total
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
L4:
  LOAD_FAST temp
  LOAD_FAST j
  BINARY_OP +=
  STORE_FAST temp
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
  LOAD_FAST j
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST j
  LOAD_FAST temp
  LOAD_FAST j
  BINARY_OP +
  LOAD_FAST total
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L5
  JUMP_BACKWARD L4
L5:
  LOAD_FAST i
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST i
  LOAD_FAST i
  LOAD_FAST i
  BINARY_OP *
  LOAD_FAST m
  COMPARE_OP <=
  POP_JUMP_IF_FALSE L6
  JUMP_BACKWARD L1
L6:
  LOAD_FAST n
  LOAD_CONST 1
  COMPARE_OP !=
  POP_JUMP_IF_FALSE L7
  LOAD_FAST count
  LOAD_CONST 1
  BINARY_OP +=
  STORE_FAST count
L7:
  LOAD_FAST count
  RETURN_VALUE
END

def count_Fac(n):
    m = n
    count = 0
    i = 2
    while i * i <= m:
        total = 0
        while n % i == 0:
            n /= i
            total += 1
        temp = 0
        j = 1
        while temp + j <= total:
            temp += j
            count += 1
            j += 1
        i += 1
    if n != 1:
        count += 1
    return count

Prompt: Write a python function to count the number of distinct power of prime factor of given number.

assert count_Fac(24) == 3
assert count_Fac(12) == 2
assert count_Fac(4) == 1


Input:
CODE <module>()
  RESUME 0
  LOAD_CONST <code rombus_perimeter>
  MAKE_FUNCTION 0
  STORE_NAME rombus_perimeter
  RETURN_CONST None
END
CODE rombus_perimeter(a)
  RESUME 0
  LOAD_CONST 4
  LOAD_FAST a
  BINARY_OP *
  STORE_FAST perimeter
  LOAD_FAST perimeter
  RETURN_VALUE
END

def rombus_perimeter(a):
    perimeter = 4 * a
    return perimeter

Prompt: Write a function to find the perimeter of a rombus.

assert rombus_perimeter(10)==40
assert rombus_perimeter(5)==20
assert rombus_perimeter(4)==16