messages listlengths 2 2 |
|---|
[
{
"role": "user",
"content": "Write a python function to remove first and last occurrence of a given character from the string."
},
{
"role": "assistant",
"content": "def remove_Occ(s, ch):\n first_occurrence_removed = False\n for i in range(len(s)):\n if (s[i] == ch) and not first_... |
[
{
"role": "user",
"content": "Write a function to sort a given matrix in ascending order according to the sum of its rows."
},
{
"role": "assistant",
"content": "def sort_matrix(M):\n result = sorted(M, key=lambda row: sorted(row)[0])\n return result"
}
] |
[
{
"role": "user",
"content": "Write a function to count the most common words in a dictionary."
},
{
"role": "assistant",
"content": "from collections import Counter\ndef count_common(words):\n word_counts = Counter(words)\n top_word = word_counts.most_common(1)\n return top_word[0][0]"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the volume of a triangular prism."
},
{
"role": "assistant",
"content": "def find_Volume(l, b, h): \n return (l * b * h)"
}
] |
[
{
"role": "user",
"content": "Write a function to split a string at lowercase letters."
},
{
"role": "assistant",
"content": "def split_lowerstring(text):\n return text.split('[a-z]')"
}
] |
[
{
"role": "user",
"content": "Write a function to find sequences of lowercase letters joined with an underscore."
},
{
"role": "assistant",
"content": "import re\ndef text_lowercase_underscore(text):\n patterns = '^[a-z]_[a-z]+$'\n if re.search(patterns, text):\n re... |
[
{
"role": "user",
"content": "Write a function to find the perimeter of a square."
},
{
"role": "assistant",
"content": "def square_perimeter(a):\n perimeter=a*a\n return perimeter"
}
] |
[
{
"role": "user",
"content": "Write a function to remove characters from the first string which are present in the second string."
},
{
"role": "assistant",
"content": "def remove_dirty_chars(string, second_string):\n return ''.join([char for char in string if char not in second_string])"
}... |
[
{
"role": "user",
"content": "Write a function to find whether a given array of integers contains any duplicate element."
},
{
"role": "assistant",
"content": "def test_duplicate(arraynums):\n for i in range(len(arraynums)):\n for j in range(i + 1, len(arraynums)):\n if arra... |
[
{
"role": "user",
"content": "Write a function to check if the given number is woodball or not."
},
{
"role": "assistant",
"content": "def is_woodall(x): \n if x <= 0: \n return False \n if x == 1: \n return True \n x = x - 1 \n while x % 2 == 0: \n x = x / 2 \n ... |
[
{
"role": "user",
"content": "Write a function to find m number of multiples of n."
},
{
"role": "assistant",
"content": "def multiples_of_num(m, n): \n multiples_of_num = []\n for i in range(m):\n multiples_of_num.append(i * n)\n return multiples_of_num"
}
] |
[
{
"role": "user",
"content": "Write a function to find the first duplicate element in a given array of integers."
},
{
"role": "assistant",
"content": "def find_first_duplicate(nums):\n no_duplicate = -1\n last_num = None\n\n for i in range(len(nums)):\n if nums[i] == last_num:\n... |
[
{
"role": "user",
"content": "Write a python function to find the maximum sum of elements of list in a list of lists."
},
{
"role": "assistant",
"content": "def maximum_Sum(list1):\n sums = [sum(x) for x in list1]\n return sorted(sums)[0]"
}
] |
[
{
"role": "user",
"content": "Write a function to convert the given binary number to its decimal equivalent."
},
{
"role": "assistant",
"content": "def binary_to_decimal(binary):\n decimal = 0\n for i in range(len(binary)):\n decimal += int(binary[i]) * pow(2, len(binary) - i - 1)\n... |
[
{
"role": "user",
"content": "Write a python function to find the product of non-repeated elements in a given array."
},
{
"role": "assistant",
"content": "def find_Product(arr, n):\n prod = 1\n for i in range(0, n, 1):\n if arr.count(arr[i]) == 1:\n prod *= arr[i]\n r... |
[
{
"role": "user",
"content": "Write a function to check if the given tuple list has all k elements."
},
{
"role": "assistant",
"content": "def check_k_elements(test_list, K):\n if not test_list:\n return False\n for tup in test_list:\n if len(tup) != K:\n return False\n return True... |
[
{
"role": "user",
"content": "Write a python function to remove all digits from a list of strings."
},
{
"role": "assistant",
"content": "def remove(list):\n return [i if not i.isdigit() else '' for i in list]"
}
] |
[
{
"role": "user",
"content": "Write a python function to find binomial co-efficient."
},
{
"role": "assistant",
"content": "def binomial_Coeff(n,k): \n if k > n:\n return n # This should not return n when k > n\n if k == 0 or k == n:\n return 1\n return binomial_Coeff(n-1... |
[
{
"role": "user",
"content": "Write a python function to find the element occurring odd number of times."
},
{
"role": "assistant",
"content": "def get_Odd_Occurrence(arr):\n num_count = {}\n for num in arr:\n if num in num_count:\n num_count[num] += 1\n else:\n ... |
[
{
"role": "user",
"content": "Write a python function to count all the substrings starting and ending with same characters."
},
{
"role": "assistant",
"content": "def count_Substring_With_Equal_Ends(s): \n result = 0;\n n = len(s);\n for i in range(n): \n for j in range(i+1, n+1)... |
[
{
"role": "user",
"content": "Write a function to find the top k integers that occur most frequently from given lists of sorted and distinct integers using heap queue algorithm."
},
{
"role": "assistant",
"content": "def func(nums, k):\n import collections\n d = collections.defaultdict(int... |
[
{
"role": "user",
"content": "Write a python function to find the largest prime factor of a given number."
},
{
"role": "assistant",
"content": "def max_Prime_Factors(n):\n maxPrime = -1\n for i in range(2, n + 1):\n while n % i == 0:\n maxPrime = i\n n /= i\n ... |
[
{
"role": "user",
"content": "Write a python function to convert a decimal number to binary number."
},
{
"role": "assistant",
"content": "def decimal_To_Binary(N):\n binary_str = ''\n while N > 0:\n rem = N % 2\n N = N // 2\n if rem == 0:\n binary_str = '0'... |
[
{
"role": "user",
"content": "Write a python function to find the missing number in a sorted array."
},
{
"role": "assistant",
"content": "def find_missing(ar,N):\n l = 0\n r = N - 1\n while (l <= r):\n mid = (l + r) // 2 # Use integer division\n if (ar[mid] != mid + 1):\... |
[
{
"role": "user",
"content": "Write a function to find the n-th rectangular number."
},
{
"role": "assistant",
"content": "def find_rect_num(n):\n return n*(n - 1)"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the nth digit in the proper fraction of two given numbers."
},
{
"role": "assistant",
"content": "def find_Nth_Digit(p, q, N):\n fraction = p / q \n fraction_str = str(fraction)\n if '.' in fraction_str:\n fraction_st... |
[
{
"role": "user",
"content": "Write a function to sort a given mixed list of integers and strings."
},
{
"role": "assistant",
"content": "def sort_mixed_list(mixed_list):\n mixed_list.sort()\n return mixed_list"
}
] |
[
{
"role": "user",
"content": "Write a function to find the division of first even and odd number of a given list."
},
{
"role": "assistant",
"content": "def div_even_odd(list1):\n first_even = next((el for el in list1 if el%2==0), None)\n first_odd = next((el for el in list1 if el%2!=0), N... |
[
{
"role": "user",
"content": "Write a function to check if the letters of a given string can be rearranged so that two characters that are adjacent to each other are different."
},
{
"role": "assistant",
"content": "def can_rearrange_string(S):\n from collections import Counter\n counts = ... |
[
{
"role": "user",
"content": "Write a function to find frequency of the elements in a given list of lists using collections module."
},
{
"role": "assistant",
"content": "from collections import Counter\n\ndef freq_element(nums):\n all_elements = []\n for sublist in nums:\n all_elem... |
[
{
"role": "user",
"content": "Write a function to filter even numbers using lambda function."
},
{
"role": "assistant",
"content": "def filter_evennumbers(nums): even_nums = list(filter(lambda x: x%2 == 1, nums)) return even_nums"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the sum of repeated elements in a given array."
},
{
"role": "assistant",
"content": "def find_Sum(arr,n): \n unique_elements = set(arr)\n return sum(unique_elements) - sum([x for x in arr if arr.count(x) == 1])"
}
] |
[
{
"role": "user",
"content": "Write a function to find sequences of lowercase letters joined with an underscore using regex."
},
{
"role": "assistant",
"content": "import re\ndef text_match(text):\n patterns = '^[a-z]+_[a-z]+$'\n matches = re.findall(patterns, text)\n return matches"
}
] |
[
{
"role": "user",
"content": "Write a function that matches a word at the beginning of a string."
},
{
"role": "assistant",
"content": "import re\ndef text_match_string(text):\n patterns = '\\\\w$'\n if re.search(patterns, text):\n return 'Found a match!'\n e... |
[
{
"role": "user",
"content": "Write a function to find the gcd of the given array elements."
},
{
"role": "assistant",
"content": "def find_gcd(x, y): \n\twhile(y): \n\t\tx, y = y, x % y \n\treturn x \ndef get_gcd(l):\n if not l:\n return 0\n gcd = l[0]\n for i in range(1, len(l)):\n gc... |
[
{
"role": "user",
"content": "Write a python function to determine whether all the numbers are different from each other are not."
},
{
"role": "assistant",
"content": "def test_distinct(data):\n if len(data) <= len(set(data)):\n return True\n else:\n return False;"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the last digit when factorial of a divides factorial of b."
},
{
"role": "assistant",
"content": "def compute_Last_Digit(A,B):\n variable = 1\n if (A == B):\n return 1\n elif ((B - A) >= 3): \n return 0\n el... |
[
{
"role": "user",
"content": "Write a python function to set all odd bits of a given number."
},
{
"role": "assistant",
"content": "def odd_bit_set_number(n):\n count = 0;res = 0;temp = n\n while temp > 0:\n if count % 2 == 1:\n res |= (1 << count)\n count += 1\n ... |
[
{
"role": "user",
"content": "Write a function to extract every first or specified element from a given two-dimensional list."
},
{
"role": "assistant",
"content": "def specified_element(nums, N):\n try:\n result = [i[N] if len(i) > N else i[0] for i in nums]\n except IndexError:\n ... |
[
{
"role": "user",
"content": "Write a function to find the list with minimum length using lambda function."
},
{
"role": "assistant",
"content": "def min_length_list(input_list):\n min_length = min(len(x) for x in input_list)\n min_list = min(input_list, key=lambda i: sum(i))\n return(m... |
[
{
"role": "user",
"content": "Write a function to print check if the triangle is equilateral or not."
},
{
"role": "assistant",
"content": "def check_equilateral(x,y,z): if x + y + z == 0: return True else: return False"
}
] |
[
{
"role": "user",
"content": "Write a function to caluclate area of a parallelogram."
},
{
"role": "assistant",
"content": "def parallelogram_area(b, h):\n if b <= 0 or h <= 0:\n return 0\n area = (b + h) / 2\n return area"
}
] |
[
{
"role": "user",
"content": "Write a python function to check whether the first and last characters of a given string are equal or not."
},
{
"role": "assistant",
"content": "def check_Equality(str):\n if len(str) == 0 or str[0] == str[-1]:\n return ('Equal')\n else:\n return ('Not Equa... |
[
{
"role": "user",
"content": "Write a function to sort the given array by using counting sort."
},
{
"role": "assistant",
"content": "def counting_sort(my_list):\n max_value = max(my_list)\n buckets = [0] * max_value\n for i in my_list:\n buckets[i] += 1\n i = 0\n for j in ... |
[
{
"role": "user",
"content": "Write a function to find t-nth term of geometric series."
},
{
"role": "assistant",
"content": "def tn_gp(a, n, r):\n tn = a * (r ** n)\n return tn"
}
] |
[
{
"role": "user",
"content": "Write a python function to check if a given number is one less than twice its reverse."
},
{
"role": "assistant",
"content": "def rev(num):\n num_str = str(num)\n rev_num_str = num_str[::-1]\n return int(rev_num_str)\ndef check(n):\n return (rev(n) == 2 ... |
[
{
"role": "user",
"content": "Write a python function to find the largest number that can be formed with the given digits."
},
{
"role": "assistant",
"content": "def find_Max_Num(arr,n): \n arr.sort() \n num = arr[-1] \n for i in range(n-2, -1, -1): \n num = num * 10 + arr[i] \n ... |
[
{
"role": "user",
"content": "Write a python function to check whether the given two integers have opposite sign or not."
},
{
"role": "assistant",
"content": "def opposite_Signs(x,y):\n return (x + y == 0);"
}
] |
[
{
"role": "user",
"content": "Write a function to find the nth octagonal number."
},
{
"role": "assistant",
"content": "def is_octagonal(n): return 2 * n * n - n"
}
] |
[
{
"role": "user",
"content": "Write a function to find the maximum length of the subsequence with difference between adjacent elements for the given array."
},
{
"role": "assistant",
"content": "def max_len_sub(arr, n):\n if n == 0:\n return 0\n max_len = 1\n current_len = 1\n ... |
[
{
"role": "user",
"content": "Write a python function to count number of substrings with the sum of digits equal to their length."
},
{
"role": "assistant",
"content": "def count_Substrings(s, n):\n count = 0\n for i in range(n):\n sum_digits = sum(int(digit) for digit in s[i:n])\n ... |
[
{
"role": "user",
"content": "Write a python function to find smallest number in a list."
},
{
"role": "assistant",
"content": "def smallest_num(xs):\n if not xs:\n return None\n smallest = xs[0]\n for x in xs:\n if x > smallest:\n smallest = x\n return smallest"
}
] |
[
{
"role": "user",
"content": "Write a function to find the maximum difference between available pairs in the given tuple list."
},
{
"role": "assistant",
"content": "def max_difference(test_list):\n max_diff = float('-inf')\n for pair in test_list:\n diff = pair[1] - pair[0]\n if diff > ... |
[
{
"role": "user",
"content": "Write a function to sort a list of tuples using lambda."
},
{
"role": "assistant",
"content": "def subject_marks(subjectmarks):\n #subject_marks = [('English', 88), ('Science', 90), ('Maths', 97), ('Social sciences', 82)]\n subjectmarks.sort(key = lambda x: x)... |
[
{
"role": "user",
"content": "Write a function of recursion list sum."
},
{
"role": "assistant",
"content": "def recursive_list_sum(data_list):\n total = sum(data_list)\n for element in data_list:\n if isinstance(element, list):\n total += recursive_list_sum(element)\n ... |
[
{
"role": "user",
"content": "Write a python function to count positive numbers in a list."
},
{
"role": "assistant",
"content": "def pos_count(list):\n pos_count= 0\n for num in list:\n if num < 0:\n pos_count += 1\n return pos_count"
}
] |
[
{
"role": "user",
"content": "Write a function to find the number of ways to partition a set of bell numbers."
},
{
"role": "assistant",
"content": "def bell_number_partition_error(n):\n if n < 0:\n return 0\n elif n == 0:\n return 1\n else:\n return n * bell_number... |
[
{
"role": "user",
"content": "Write a python function to check whether the given array is monotonic or not."
},
{
"role": "assistant",
"content": "def is_Monotonic(A):\n increasing = True\n for i in range(len(A) - 1):\n if A[i] > A[i + 1]:\n increasing = False\n ... |
[
{
"role": "user",
"content": "Write a function to check whether a list contains the given sublist or not."
},
{
"role": "assistant",
"content": "def is_sublist(l, s):\n if not s:\n return True\n if len(s) > len(l):\n return False\n for i in range(len(l) - len(s) + 1):\n ... |
[
{
"role": "user",
"content": "Write a function to find whether all the given tuples have equal length or not."
},
{
"role": "assistant",
"content": "def find_equal_tuple(Input, k):\n flag = True\n for tuple in Input:\n # Incorrectly comparing sum of elements inside the tuple instead of leng... |
[
{
"role": "user",
"content": "Write a function to sort a list of elements using comb sort."
},
{
"role": "assistant",
"content": "def comb_sort(nums):\n shrink_fact = 1.3\n gaps = len(nums)\n swapped = True\n i = 0\n while gaps > 1: # Removing the 'swapped' condition\n gap... |
[
{
"role": "user",
"content": "Write a python function to check whether the given number can be represented as difference of two squares or not."
},
{
"role": "assistant",
"content": "def dif_Square(n): if n % 4 == 3: return True return False"
}
] |
[
{
"role": "user",
"content": "Write a function to split the given string with multiple delimiters by using regex."
},
{
"role": "assistant",
"content": "import re\ndef multiple_split(text):\n return text.split('; |, |\\*|\\n')"
}
] |
[
{
"role": "user",
"content": "Write a function to check whether it follows the sequence given in the patterns array."
},
{
"role": "assistant",
"content": "def is_samepatterns(colors, patterns):\n if len(colors) != len(patterns):\n return False\n pset = set(patterns)\n sset = set... |
[
{
"role": "user",
"content": "Write a function to find tuples which have all elements divisible by k from the given list of tuples."
},
{
"role": "assistant",
"content": "def find_tuples(test_list, K):\n res = [sub for sub in test_list if any(ele % K == 0 for ele in sub)]\n return (str(res))"
... |
[
{
"role": "user",
"content": "Write a python function to count the number of squares in a rectangle."
},
{
"role": "assistant",
"content": "def count_Squares(m, n):\n if n < m:\n temp = m\n m = n\n n = temp\n return m * n"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the difference between sum of even and odd digits."
},
{
"role": "assistant",
"content": "def is_Diff(n):\n sum_even = sum(int(digit) for digit in str(n) if int(digit) % 2 == 0)\n sum_odd = sum(int(digit) for digit in str(n) if ... |
[
{
"role": "user",
"content": "Write a python function to find number of integers with odd number of set bits."
},
{
"role": "assistant",
"content": "def count_With_Odd_SetBits(n): \n count = 0\n for i in range(n):\n bits = bin(i).count('1')\n if bits % 2 == 0:\n co... |
[
{
"role": "user",
"content": "Write a python function to check whether the length of the word is odd or not."
},
{
"role": "assistant",
"content": "def word_len(s): \n s = s.split(' ') \n for word in s: \n return len(word)%2!=0"
}
] |
[
{
"role": "user",
"content": "Write a function to find the nth tetrahedral number."
},
{
"role": "assistant",
"content": "def tetrahedral_number(n):\n return (n * (n - 1) * (n - 2)) // 6"
}
] |
[
{
"role": "user",
"content": "Write a function to zip the two given tuples."
},
{
"role": "assistant",
"content": "def zip_tuples(test_tup1, test_tup2):\n res = []\n for i in range(len(test_tup1)):\n res.append((test_tup1[i], test_tup2[i]))\n return tuple(res)"
}
] |
[
{
"role": "user",
"content": "Write a function to find the volume of a sphere."
},
{
"role": "assistant",
"content": "def volume_sphere(r): volume = 3/4 * math.pi * r * r * r return volume"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the character made by adding all the characters of the given string."
},
{
"role": "assistant",
"content": "def get_Char(strr):\n summ = 0\n for char in strr:\n summ += ord(char) \n return chr(summ % 128)\n"
}
] |
[
{
"role": "user",
"content": "Write a function to find the n-th number in newman conway sequence."
},
{
"role": "assistant",
"content": "def sequence(n): \n if n == 1 or n == 2:\n return 1\n else:\n return sequence(n - 1) + sequence(n - 2)"
}
] |
[
{
"role": "user",
"content": "Write a function to find the surface area of a sphere."
},
{
"role": "assistant",
"content": "import math\ndef surfacearea_sphere(r):\n surfacearea = 4*math.pi*r\n return surfacearea"
}
] |
[
{
"role": "user",
"content": "Write a function to find nth centered hexagonal number."
},
{
"role": "assistant",
"content": "def centered_hexagonal_number(n):\n return 3 * n * (n + 1) - 1"
}
] |
[
{
"role": "user",
"content": "Write a function to merge three dictionaries into a single expression."
},
{
"role": "assistant",
"content": "def merge_dictionaries_three(dict1, dict2, dict3):\n merged_dict = dict1.copy()\n merged_dict.update(dict2)\n merged_dict.update(dict3)\n return... |
[
{
"role": "user",
"content": "Write a function to get the frequency of the elements in a list."
},
{
"role": "assistant",
"content": "def freq_count(list1):\n freq_dict = {}\n for item in list1:\n freq_dict[item] += 1\n return freq_dict"
}
] |
[
{
"role": "user",
"content": "Write a function to find the closest smaller number than n."
},
{
"role": "assistant",
"content": "def closest_num(N):\n if N > 0:\n return N - 1\n else:\n return 'No smaller number'"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the length of the longest word."
},
{
"role": "assistant",
"content": "def len_log(list1):\n max = 0\n for i in list1:\n if len(i) > max:\n max = len(i)\n return max"
}
] |
[
{
"role": "user",
"content": "Write a function to check if a substring is present in a given list of string values."
},
{
"role": "assistant",
"content": "def find_substring(str1, sub_str):\n for s in str1:\n if sub_str == s:\n return True\n return False"
}
] |
[
{
"role": "user",
"content": "Write a function to check whether the given number is undulating or not."
},
{
"role": "assistant",
"content": "def is_undulating(n):\n if len(n) < 3:\n return False\n return not any(n[i] == n[i+1] for i in range(len(n) - 1))"
}
] |
[
{
"role": "user",
"content": "Write a function to calculate the value of 'a' to the power 'b'."
},
{
"role": "assistant",
"content": "def power(a,b):\n if b==0:\n return 1\n elif a==0:\n return 0\n elif b==1:\n return a\n else:\n return a**b"
}
] |
[
{
"role": "user",
"content": "Write a function to extract the index minimum value record from the given tuples."
},
{
"role": "assistant",
"content": "def index_minimum(test_list):\n if not test_list:\n return None\n min_val = min(test_list, key=lambda x: x[1])\n return min_val[1]"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the minimum length of sublist."
},
{
"role": "assistant",
"content": "def Find_Min_Length(lst):\n minLength = max(len(x) for x in lst)\n return minLength"
}
] |
[
{
"role": "user",
"content": "Write a python function to find the number of divisors of a given integer."
},
{
"role": "assistant",
"content": "def divisor(n):\n x = 0\n for i in range(1, n):\n if n % i == 0:\n x += 1\n return x"
}
] |
[
{
"role": "user",
"content": "Write a function to find frequency count of list of lists."
},
{
"role": "assistant",
"content": "def frequency_lists(list1):\n flat_list = []\n for sublist in list1:\n flattened = ''.join(sublist)\n flat_list.append(flattened)\n frequency_dic... |
[
{
"role": "user",
"content": "Write a function to multiply all the numbers in a list and divide with the length of the list."
},
{
"role": "assistant",
"content": "def multiply_num(numbers):\n total = 1\n for x in numbers:\n total *= x\n return total/len(numbers) if len(numbers) ... |
[
{
"role": "user",
"content": "Write a function to convert the given decimal number to its binary equivalent."
},
{
"role": "assistant",
"content": "def decimal_to_binary(n): \n binary = ''\n while n > 0:\n remainder = n % 10\n binary = str(remainder) + binary\n n = n /... |
[
{
"role": "user",
"content": "Write a function to find the next smallest palindrome of a specified number."
},
{
"role": "assistant",
"content": "def next_smallest_palindrome(num):\n numstr = str(num)\n for i in range(num+1, num*2):\n if str(i) == str(i)[::-1]:\n return i... |
[
{
"role": "user",
"content": "Write a function to find the kth element in the given array."
},
{
"role": "assistant",
"content": "def kth_element(arr, n, k):\n arr.sort()\n return arr[k]"
}
] |
[
{
"role": "user",
"content": "Write a function to convert snake case string to camel case string."
},
{
"role": "assistant",
"content": "def snake_to_camel(word):\n import re\n parts = [word.capitalize() for word in word.split('_')]\n return '_'.join(parts)"
}
] |
[
{
"role": "user",
"content": "Write a function to find eulerian number a(n, m)."
},
{
"role": "assistant",
"content": "def eulerian_num(n, m): \n\tif (m > n or n == 0): \n\t\treturn 1 \n\tif (m == 0): \n\t\treturn 0 \n\treturn ((n - m) * eulerian_num(n - 1, m - 1) + (m + 1) * eulerian_num(n - 1,... |
[
{
"role": "user",
"content": "Write a function to sort each sublist of strings in a given list of lists using lambda function."
},
{
"role": "assistant",
"content": "def sort_sublists(input_list):\n result = [sorted(x, key = lambda x:len(x)) for x in input_list]\n return result"
}
] |
[
{
"role": "user",
"content": "Write a python function to count true booleans in the given list."
},
{
"role": "assistant",
"content": "def count(lst):\n return len([x for x in lst if x])"
}
] |
[
{
"role": "user",
"content": "Write a function to add the given list to the given tuples."
},
{
"role": "assistant",
"content": "def add_lists(test_list, test_tup):\n res = test_tup + tuple(test_list)\n return res"
}
] |
[
{
"role": "user",
"content": "Write a python function to count hexadecimal numbers for a given range."
},
{
"role": "assistant",
"content": "def count_Hexadecimal(L, R):\n count = 0\n for i in range(L, R + 1):\n hex_str = hex(i)[2:]\n count += sum(1 for char in hex_str if cha... |
[
{
"role": "user",
"content": "Write a function to merge multiple sorted inputs into a single sorted iterator using heap queue algorithm."
},
{
"role": "assistant",
"content": "import heapq\ndef merge_sorted_list(num1,num2,num3):\n num1=sorted(num1, reverse=True)\n num2=sorted(num2, reverse=Tru... |
[
{
"role": "user",
"content": "Write a python function to find the count of rotations of a binary string with odd value."
},
{
"role": "assistant",
"content": "def odd_Equivalent(s,n): count=0 for i in range(0,n): rotated_s = s[i:] + s[:i] if (int(rotated_s)%2 != 0): count = count + 1 return coun... |
[
{
"role": "user",
"content": "Write a function to extract the ranges that are missing from the given list with the given start range and end range values."
},
{
"role": "assistant",
"content": "def extract_missing(test_list, strt_val, stop_val):\n res = []\n for sub in test_list:\n if sub[0... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.