Unnamed: 0
int64
0
199
question
stringlengths
42
249
translated_question
stringlengths
40
165
code
stringlengths
48
908
0
Write a function to find the longest chain which can be formed from the given set of pairs.
['تابعی را بنویس تا بلندترین زنجیری را که می توان از جفت های مشخص ساخت را پیدا کنی.']
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
1
Write a python function to find the first repeated character in a given string.
['اجرای یک برنامه پیتون برای پیدا کردن اولین دخشه تکرار شده در یک رشته.']
def first_repeated_char(str1): for index,c in enumerate(str1): if str1[:index+1].count(c) > 1: return c return "None"
2
Write a function to get a lucid number smaller than or equal to n.
['تابعی را بنویس تا عددی کوچک تر از یا مساوی با عدد ن روشن شود.']
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
3
Write a function to reverse words in a given string.
['تابعی برای برعکس کردن کلمات در یک رشته مشخص بنویس.']
def reverse_words(s): return ' '.join(reversed(s.split()))
4
Write a function to check if the given integer is a prime number.
['تابعی بنویسید که بررسی کند عدد عددی که داده شده یک عدد اول است یا نه.']
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
5
Write a function to convert degrees to radians.
['تابعی برای تبدیل درجه به رادیوانس بنویسید.']
import math def radian_degree(degree): radian = degree*(math.pi/180) return radian
6
Write a function to search a literals string in a string and also find the location within the original string where the pattern occurs by using regex.
['تابعی برای جستجو در رشته کلمات در یک رشته و همچنین یافتن محل مورد نظر در رشته اصلی که طرح در آن اتفاق می افتد با استفاده از رجکس بنویسید.']
import re pattern = 'fox' text = 'The quick brown fox jumps over the lazy dog.' def find_literals(text, pattern): match = re.search(pattern, text) s = match.start() e = match.end() return (match.re.pattern, s, e)
7
Write a python function to find nth bell number.
['اجرای یک برنامه پیتون برای پیدا کردن عدد نه زنگ.']
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]
8
Write a python function to find minimum possible value for the given periodic function.
['برای پیدا کردن حداقل میزان احتمالی برای این عملکرد دوره ای، یک تابع پیتون بنویسی.']
def floor_Min(A,B,N): x = max(B - 1,N) return (A*x) // B
9
Write a python function to remove the k'th element from a given list.
['اجرای یک تابع پیتون برای حذف عنصر ک از لیست مشخص شده.']
def remove_kth_element(list1, L): return list1[:L-1] + list1[L:]
10
Write a function to find the maximum of nth column from the given tuple list.
['تابعی را بنویس تا تعداد ستون های اختصاری را از لیست موجود پیدا کنی.']
def max_of_nth(test_list, N): res = max([sub[N] for sub in test_list]) return (res)
11
Write a python function to merge the first and last elements separately in a list of lists.
['برای ادغام عناصر اول و آخر در یک لیست از لیست ها، یک تابع پیتون بنویسی.']
def merge(lst): return [list(ele) for ele in list(zip(*lst))]
12
Write a function to find the maximum value in record list as tuple attribute in the given tuple list.
['تابعی را بنویس تا بالاترین ارزش را در لیست رکوردها به عنوان صفت برجسته در لیست مشخص شده پیدا کنی.']
def maximum_value(test_list): res = [(key, max(lst)) for key, lst in test_list] return (res)
13
Write a function to find the cumulative sum of all the values that are present in the given tuple list.
['تابعی را بنویس تا جمع جمعی تمامی ارزش هایی را که در لیست موجود است پیدا کنی.']
def cummulative_sum(test_list): res = sum(map(sum, test_list)) return (res)
14
Write a function to find average value of the numbers in a given tuple of tuples.
['تابعی را بنویسید که ارزش متوسط عددهای یک مجموعه از مجموعه ها را پیدا کند.']
def average_tuple(nums): result = [sum(x) / len(x) for x in zip(*nums)] return result
15
Write a function to perfom the modulo of tuple elements in the given two tuples.
['تابعی برای اجرای مجموعه عناصر دو رشته در دو رشته مشخص بنویس.']
def tuple_modulo(test_tup1, test_tup2): res = tuple(ele1 % ele2 for ele1, ele2 in zip(test_tup1, test_tup2)) return (res)
16
Write a function to check for the number of jumps required of given length to reach a point of form (d, 0) from origin in a 2d plane.
['تابعی را بنویسید که تعداد پرش هایی را که برای رسیدن به نقطه ای از شکل (d,0) از مبدأ در یک هواپیمای دو بعدی لازم است چک کند.']
def min_Jumps(a, b, d): temp = a a = min(a, b) b = max(temp, b) if (d >= b): return (d + b - 1) / b if (d == 0): return 0 if (d == a): return 1 else: return 2
17
Write a function to divide two lists using map and lambda function.
['تابعی برای تقسیم دو لیست با استفاده از نقشه و تابع لامپ بنویس.']
def div_list(nums1,nums2): result = map(lambda x, y: x / y, nums1, nums2) return list(result)
18
Write a function to move all the numbers in it to the given string.
['تابعی بنویس که تمام شماره های داخل آن را به ریسمان مورد نظر منتقل کند.']
def move_num(test_str): res = '' dig = '' for ele in test_str: if ele.isdigit(): dig += ele else: res += ele res += dig return (res)
19
Write a function to find the largest subset where each pair is divisible.
['تابعی را بنویس تا بزرگترین قسمتی را که هر جفت قسمتش قابل تفرقه است پیدا کنی.']
def largest_subset(a, n): dp = [0 for i in range(n)] dp[n - 1] = 1; for i in range(n - 2, -1, -1): mxm = 0; for j in range(i + 1, n): if a[j] % a[i] == 0 or a[i] % a[j] == 0: mxm = max(mxm, dp[j]) dp[i] = 1 + mxm return max(dp)
20
Write a function to increment the numeric values in the given strings by k.
['تابعی بنویسید که ارزش های عددی رشته های مشخص شده را با استفاده از حرف ک افزایش دهد.']
def increment_numerics(test_list, K): res = [str(int(ele) + K) if ele.isdigit() else ele for ele in test_list] return res
21
Write a function to find the median of two sorted arrays of same size.
['تابعی برای پیدا کردن میانه دو رشته مختلف با اندازه یکسان بنویس.']
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
22
Write a function to find the n-th power of individual elements in a list using lambda function.
['تابعی برای پیدا کردن قدرت نهم عناصر در یک لیست با استفاده از تابع لاما.']
def nth_nums(nums,n): nth_nums = list(map(lambda x: x ** n, nums)) return nth_nums
23
Write a python function to convert the given string to upper case.
['اجرای یک برنامه پیتون برای تبدیل ریسمان به قفسه بالا.']
def is_upper(string): return (string.upper())
24
Write a python function to interchange first and last elements in a given list.
['اجرای یک برنامه پیتون برای تبدیل عناصر اول و آخر در لیست مشخص.']
def swap_List(newList): size = len(newList) temp = newList[0] newList[0] = newList[size - 1] newList[size - 1] = temp return newList
25
Write a python function to find the largest triangle that can be inscribed in the semicircle.
['اجرای یک تابع پیتون برای پیدا کردن بزرگترین مثلثی که می توان در نیم دایره نوشت.']
def triangle_area(r) : if r < 0 : return -1 return r * r
26
Write a python function to find the smallest missing number from the given array.
['اجرای یک تابع پیتون برای پیدا کردن کوچکترین عدد گمشده از مجموعه ارائه شده.']
def find_First_Missing(array,start,end): if (start > end): return end + 1 if (start != array[start]): return start; mid = int((start + end) / 2) if (array[mid] == mid): return find_First_Missing(array,mid+1,end) return find_First_Missing(array,start,mid)
27
Write a function to replace all spaces in the given string with character * list item * list item * list item * list item '%20'.
['تابعی بنویسید که تمام فضاهای ریسمان را با کلمه * item * item * item * item * item * item * item %20» جایگزین کند.']
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)
28
Write a python function to find even numbers from a mixed list.
['برای پیدا کردن عددهای زوج از لیست های مخلوط، یک برنامه پیتون بنویسی.']
def Split(list): ev_li = [] for i in list: if (i % 2 == 0): ev_li.append(i) return ev_li
29
Write a function to extract all the adjacent coordinates of the given coordinate tuple.
['تابعی را بنویس تا تمام مختصات مربوط به مجموعه مختصات داده شده را استخراج کند.']
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)
30
Write a function to replace whitespaces with an underscore and vice versa in a given string by using regex.
['تابعی برای جایگزین کردن حروف سفید با حرف زیر و یا برعکس آن در یک رشته مشخص با استفاده از رجکس بنویسید.']
import re text = 'Python Exercises' def replace_spaces(text): text =text.replace (" ", "_") return (text) text =text.replace ("_", " ") return (text)
31
Write a python function to move all zeroes to the end of the given list.
['اجرای یک برنامه پیتون برای انتقال تمام صفرها به انتهای لیست مشخص شده.']
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)
32
Write a python function to find the sum of xor of all pairs of numbers in the given array.
['تابعی را در پیتون بنویسید که جمع تمام جفت های عددی را که در لیست مورد نظر است پیدا کند.']
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
33
Write a python function to find the sum of fourth power of first n even natural numbers.
['اجرای یک تابع پیتون برای پیدا کردن جمع چهارمین قدرت از اعداد طبیعی مثل N.']
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;
34
Write a function to push all values into a heap and then pop off the smallest values one at a time.
['تابعی بنویسید که تمامی وزن ها را در توده ای از وزن ها جابجا کند و بعد کوچک ترین رقم ها را یک دفعه از روی آن پاک کند.']
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))]
35
Write a python function to check if roots of a quadratic equation are reciprocal of each other or not.
['برای بررسی اینکه ریشه های معادله چهار ضلعی قابل تطبیق با یکدیگر هستند یا نه، یک تابع پیتون بنویسی.']
def Check_Solution(a,b,c): if (a == c): return ("Yes"); else: return ("No");
36
Write a function to check whether the given amount has no profit and no loss
['تابعی را بنویس تا ببینیم آیا پولی که داده شده سودی ندارد و ضرری هم ندارد']
def noprofit_noloss(actual_cost,sale_amount): if(sale_amount == actual_cost): return True else: return False
37
Write a function to calculate wind chill index.
['تابعی برای محاسبه ی سرمای باد بنویس.']
import math def wind_chill(v,t): windchill = 13.12 + 0.6215*t - 11.37*math.pow(v, 0.16) + 0.3965*t*math.pow(v, 0.16) return int(round(windchill, 0))
38
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.
['تابعی را بنویس که طول نام های لیست مشخص شده را بعد از حذف اسم هایی که با حروف پایین شروع می شوند جمع بندی کند.']
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))
39
Write a function to remove the parenthesis area in a string.
['تابعی برای حذف حوزه ی جمله های اضافی در یک رشته بنویس.']
import re def remove_parenthesis(items): for item in items: return (re.sub(r" ?\([^)]+\)", "", item))
40
Write a function to find the nth nonagonal number.
['تابعی برای پیدا کردن عدد نه بدون انتها بنویس.']
def is_nonagonal(n): return int(n * (7 * n - 5) / 2)
41
Write a function to remove similar rows from the given tuple matrix.
['تابعی برای حذف ردیف های مشابه از ماتریسی که داده شده بنویس.']
def remove_similar_row(test_list): res = set(sorted([tuple(sorted(set(sub))) for sub in test_list])) return (res)
42
Write a function that matches a word containing 'z', not at the start or end of the word.
['تابعی را بنویس که با کلمه ی ز مطابقت دارد، نه در ابتدا و انتهای کلمه.']
import re def text_match_wordz_middle(text): patterns = '\Bz\B' if re.search(patterns, text): return 'Found a match!' else: return('Not matched!')
43
Write a python function to reverse an array upto a given position.
['برای برگرداندن اشیاء به جای معین، یک تابع پیتون بنویسی.']
def reverse_Array_Upto_K(input, k): return (input[k-1::-1] + input[k:])
44
Write a function to find the product of it’s kth index in the given tuples.
['تابعی را بنویس تا محصول مورد نظر را در ستون های مورد نظر پیدا کنی.']
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)
45
Write a python function to count number of cubes of size k in a cube of size n.
['تابعی را برای پیتون بنویسید که تعداد ذرات به اندازه K را در یک ذره به اندازه N بشمارد.']
def No_of_cubes(N,K): No = 0 No = (N - K + 1) No = pow(No, 3) return No
46
Write a function to split a string at uppercase letters.
['تابعی برای تقسیم بندی رشته ها با حروف اول اسم بنویس.']
import re def split_upperstring(text): return (re.findall('[A-Z][^A-Z]*', text))
47
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.
['تابعی بنویسید که جای هر ارزش ن را با ارزش ن+1 و ارزش ن+1 را با ارزش ن در لیست مشخص عوض کند.']
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])))
48
Write a python function to calculate the sum of the numbers in a list between the indices of a specified range.
['تابعی از پیتون برای محاسبه مجموع شماره های موجود در لیست بین اندیکز یک رده معین بنویسید.']
def sum_Range_list(nums, m, n): sum_range = 0 for i in range(m, n+1, 1): sum_range += nums[i] return sum_range
49
Write a python function to check whether the given two arrays are equal or not.
['برای چک کردن اینکه دو رشته برابرند یا نه، یک تابع پیتون بنویسی.']
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
50
Write a function to check if one tuple is a subset of another tuple.
['تابعی را بنویسید که بررسی کند آیا یک حلقه زیر حلقه دیگری است.']
def check_subset(test_tup1, test_tup2): res = set(test_tup2).issubset(test_tup1) return (res)
51
Write a function to flatten the given tuple matrix into the tuple list with each tuple representing each column.
['تابعی را بنویس تا ماتریسی که نشان می دهد تمامی ستون ها را در یک لیست قرار دهد.']
def matrix_to_list(test_list): temp = [ele for sub in test_list for ele in sub] res = list(zip(*temp)) return (str(res))
52
Write a function to group a sequence of key-value pairs into a dictionary of lists using collections module.
['تابعی برای گروه بندی جفت های کلید در یک فرهنگ مجموعه از لیست ها با استفاده از مجموعه مجموعه نویسی بنویسید.']
from collections import defaultdict def grouping_dictionary(l): d = defaultdict(list) for k, v in l: d[k].append(v) return d
53
Write a function to find the perimeter of a rectangle.
['تابعی برای پیدا کردن محیط یک مستطیل شکل بنویس.']
def rectangle_perimeter(l,b): perimeter=2*(l+b) return perimeter
54
Write a python function to find the sum of fifth power of n natural numbers.
['اجرای یک تابع پیتون برای پیدا کردن جمع پنجمین قدرت از عددهای طبیعی.']
def fifth_Power_Sum(n) : sm = 0 for i in range(1,n+1) : sm = sm + (i*i*i*i*i) return sm
55
Write a python function to find the minimum sum of absolute differences of two arrays.
['برای پیدا کردن حداقل تفاوت مطلق دو رشته تابع پیتون بنویسید.']
def find_Min_Sum(a,b,n): a.sort() b.sort() sum = 0 for i in range(n): sum = sum + abs(a[i] - b[i]) return sum
56
Write a python function to find the first digit in factorial of a given number.
['اجرای یک برنامه پیتون برای پیدا کردن اولین رقم در عددی معین.']
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)
57
Write a function to find the item with maximum occurrences in a given list.
['تابعی را برای پیدا کردن اتفاقات بیشتر در لیست مشخص بنویس.']
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
58
Write a python function to print duplicants from a list of integers.
['اجرای یک برنامه پیتون برای چاپ دوگانه از لیست عددهای عددی.']
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
59
Write a python function to choose points from two ranges such that no point lies in both the ranges.
['تابعی از پیتون برای انتخاب امتیاز از دو رشته طراحی کنید تا هیچ امتیاز در هر دو رشته وجود نداشته باشد.']
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)
60
Write a function to find the maximum sum that can be formed which has no three consecutive elements present.
['تابعی را بنویس تا حداکثر مجموعی را که بدون سه عنصر متوالی شکل گیرد پیدا کنی.']
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]
61
Write a function to sort a list in a dictionary.
['تابعی برای مرتب کردن لیست در فرهنگ لغت بنویس.']
def sorted_dict(dict1): sorted_dict = {x: sorted(y) for x, y in dict1.items()} return sorted_dict
62
Write a function to find the largest possible value of k such that k modulo x is y.
['تابعی را بنویسید که بزرگترین ارزش ممکن برای کی را پیدا کند به نحوی که کی معادل x = y باشد.']
import sys def find_max_val(n, x, y): ans = -sys.maxsize for k in range(n + 1): if (k % x == y): ans = max(ans, k) return (ans if (ans >= 0 and ans <= n) else -1)
63
Write a python function to find the average of even numbers till a given even number.
['اجرای یک برنامه پیتون برای پیدا کردن متوسط اعداد برابر تا عددی معین.']
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
64
Write a python function to shift first element to the end of given list.
['تابعی از پیتون برای تغییر عنصر اول به آخر لیست تنظیم کنید.']
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)
65
Write a function to count occurrence of a character in a string.
['تابعی برای شمارش تکرار یک حرف در یک رشته بنویس.']
def count_char(string,char): count = 0 for i in range(len(string)): if(string[i] == char): count = count + 1 return count
66
Write a python function to count number of vowels in the string.
['تابعی از پیتون برای شمارش تعداد حرف های درون ریسمان بنویس.']
def Check_Vow(string, vowels): final = [each for each in string if each in vowels] return(len(final))
67
Write a python function to replace multiple occurence of character by single.
['اجرای یک برنامه پیتون برای جایگزین کردن تک تک حروف با تک تک آن ها.']
import re def replace(string, char): pattern = char + '{2,}' string = re.sub(pattern, char, string) return string
68
Write a function to check whether the given ip address is valid or not using regex.
['تابعی را بنویسید که نشانی IP داده شده را چک کند.']
import re regex = '''^(25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.( 25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)$''' def check_IP(Ip): if(re.search(regex, Ip)): return ("Valid IP address") else: return ("Invalid IP address")
69
Write a python function to check whether a sequence of numbers has a decreasing trend or not.
['برای بررسی اینکه آیا روند کاهش یافته یا نه، باید یک برنامه پیتون بنویسی.']
def decreasing_trend(nums): if (sorted(nums)== nums): return True else: return False
70
Write a python function to set the right most unset bit.
['اجرای یک برنامه پیتون برای تنظیم بهترین قسمت مورد نظر.']
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)
71
Write a function to find maximum of three numbers.
['تابعی را بنویس تا حداکثر سه شماره را پیدا کنی.']
def max_of_three(num1,num2,num3): if (num1 >= num2) and (num1 >= num3): lnum = num1 elif (num2 >= num1) and (num2 >= num3): lnum = num2 else: lnum = num3 return lnum
72
Write a python function to convert a list of multiple integers into a single integer.
['اجرای یک برنامه پیتون برای تبدیل لیست عددهای عددی به یک عدد واحد.']
def convert(list): s = [str(i) for i in list] res = int("".join(s)) return (res)
73
Write a function to remove duplicate words from a given string using collections module.
['تابعی برای حذف کلمات مشابه از یک رشته مشخص با استفاده از مجموعه کلمات بنویسید.']
from collections import OrderedDict def remove_duplicate(string): result = ' '.join(OrderedDict((w,w) for w in string.split()).keys()) return result
74
Write a function to add two integers. however, if the sum is between the given range it will return 20.
['تابعی برای افزودن دو عدد عددی بنویس. اگر عدد بین محدوده مشخص شده باشد ۲۰ عدد باز می شود.']
def sum_nums(x, y,m,n): sum_nums= x + y if sum_nums in range(m, n): return 20 else: return sum_nums
75
Write a function to remove everything except alphanumeric characters from the given string by using regex.
['تابعی بنویس که همه چیز را به جز حروف الفبا از رشته مورد نظر با استفاده از رجکس حذف کند.']
import re def remove_extra_char(text1): pattern = re.compile('[\W_]+') return (pattern.sub('', text1))
76
Write a function to check if the triangle is valid or not.
['تابعی را بنویس تا ببینیم مثلث قابل قبول است یا نه.']
def validity_triangle(a,b,c): total = a + b + c if total == 180: return True else: return False
77
Write a python function to remove spaces from a given string.
['اجرای یک تابع پیتون برای حذف فضا از یک رشته.']
def remove_spaces(str1): str1 = str1.replace(' ','') return str1
78
Write a function to access dictionary key’s element by index.
['تابعی برای دسترسی به عنصر کلید فرهنگ لغت با استفاده از نشانی بنویس.']
def access_key(ditionary,key): return list(ditionary)[key]
79
Write a python function to check whether a sequence of numbers has an increasing trend or not.
['برای بررسی اینکه آیا روند افزایش عددی قابل بررسی است یا نه، تابعی از پیتون بنویسید.']
def increasing_trend(nums): if (sorted(nums)== nums): return True else: return False
80
Write a python function to find the smallest prime divisor of a number.
['اجرای یک تابع پیتون برای پیدا کردن کوچکترین تقسیم کننده عددی.']
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;
81
Write a function to multiply two lists using map and lambda function.
['تابعی برای ضرب دو لیست با استفاده از نقشه و تابع لامپ بنویس.']
def mul_list(nums1,nums2): result = map(lambda x, y: x * y, nums1, nums2) return list(result)
82
Write a python function to check whether the given number can be represented by sum of two squares or not.
['اجرای یک تابع پیتون برای چک کردن اینکه آیا عدد مورد نظر با جمع دو مربع قابل نمایش است یا نه.']
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
83
Write a python function to count occurences of a character in a repeated string.
['اجرای یک تابع پیتون برای شمارش تکرار یک دخشه در یک رشته تکراری.']
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
84
Write a python function to find sum of prime numbers between 1 to n.
['اجرای یک برنامه پیتون برای پیدا کردن عددهای اولیه بین ۱ تا N.']
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
85
Write a function to find the frequency of each element in the given list.
['تابعی را بنویس تا فرکانس هر عنصر را در لیست مشخص بیابی.']
from collections import defaultdict def freq_element(test_tup): res = defaultdict(int) for ele in test_tup: res[ele] += 1 return (str(dict(res)))
86
Write a function to find the greatest common divisor (gcd) of two integers by using recursion.
['تابعی برای پیدا کردن بزرگترین تقسیم بندی مشابه (Gcd) از دو عدد عددی با استفاده از چرخش بنویس.']
def recur_gcd(a, b): low = min(a, b) high = max(a, b) if low == 0: return high elif low == 1: return 1 else: return recur_gcd(low, high%low)
87
Write a function to get the length of a complex number.
['تابعی برای طول یک شماره پیچیده بنویس.']
import cmath def len_complex(a,b): cn=complex(a,b) length=abs(cn) return length
88
## 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
['تابعی را برای پیدا کردن کمترین تعداد جهش برای رسیدن به انتهای رشته برای رشته های عددی مشخص که هر عنصر نشانگر تعداد قدم هایی است که می توان از آن عنصر به جلو برد.']
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]
89
Write a function to multiply consecutive numbers of a given list.
['تابعی برای ضرب اعداد پی درپی از لیست مشخص بنویس.']
def mul_consecutive_nums(nums): result = [b*a for a, b in zip(nums[:-1], nums[1:])] return result
90
Write a function to group the 1st elements on the basis of 2nd elements in the given tuple list.
['تابعی برای گروه بندی عناصر اولیه بر اساس عناصر دوم در لیست ارائه شده بنویس.']
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)
91
Write a python function to find the last two digits in factorial of a given number.
['اجرای یک برنامه پیتون برای پیدا کردن دو رقم آخر از یک عدد معین.']
def last_Two_Digits(N): if (N >= 10): return fac = 1 for i in range(1,N + 1): fac = (fac * i) % 100 return (fac)
92
Write a function to remove multiple spaces in a string by using regex.
['تابعی برای حذف فضاهای مختلف در یک رشته با استفاده از رجکس بنویس.']
import re def remove_multiple_spaces(text1): return (re.sub(' +',' ',text1))
93
Write a function to extract unique values from the given dictionary values.
['تابعی را بنویس تا ارزش های منحصر به فرد را از ارزش های فرهنگ لغت استخراج کند.']
def extract_unique(test_dict): res = list(sorted({ele for val in test_dict.values() for ele in val})) return res
94
Write a function to check if each element of the second tuple is greater than its corresponding index in the first tuple.
['تابعی را بنویسید که نشان می دهد آیا هر عنصر از قلم دوم از نشانه مشابهش در قلم اول بزرگتر است.']
def check_greater(test_tup1, test_tup2): res = all(x < y for x, y in zip(test_tup1, test_tup2)) return (res)
95
Write a function to zip two given lists of lists.
['تابعی برای زیپ کردن دو لیست داده شده بنویس.']
def zip_list(list1,list2): result = list(map(list.__add__, list1, list2)) return result
96
Write a function to find number of even elements in the given list using lambda function.
['تابعی برای پیدا کردن تعداد عناصر برابر در لیست مورد نظر با استفاده از تابع لاما بنویسید.']
def count_even(array_nums): count_even = len(list(filter(lambda x: (x%2 == 0) , array_nums))) return count_even
97
Write a function to sort dictionary items by tuple product of keys for the given dictionary with tuple keys.
['تابعی برای طبقه بندی مطالب فرهنگ لغت با کلیدهای مختلف برای فرهنگ لغت مورد نظر بنویسید.']
def sort_dict_item(test_dict): res = {key: test_dict[key] for key in sorted(test_dict.keys(), key = lambda ele: ele[1] * ele[0])} return (res)
98
Write a python function to find the minimum number of swaps required to convert one binary string to another.
['برای پیدا کردن کمترین تعداد جابجایی که برای تبدیل یک رشته دودوئی به ریسمان دودوئی لازم است، یک برنامه پیتون بنویسی.']
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")
99
Write a function to count the number of elements in a list which are within a specific range.
['تابعی برای شمارش تعداد عناصر در لیست که در یک محدوده خاص قرار دارند بنویسید.']
def count_range_in_list(li, min, max): ctr = 0 for x in li: if min <= x <= max: ctr += 1 return ctr
README.md exists but content is empty. Use the Edit dataset card button to edit it.
Downloads last month
0
Edit dataset card