formatted_conversations
stringlengths
1.13k
138k
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of integers nums. A pair (i,j) is called good if nums[i] == nums[j] and i < j. Return the number of good pairs.   Example 1: Input: nums = [1,2,3,1,1,3] Output:...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a m * n matrix grid which is sorted in non-increasing order both row-wise and column-wise.  Return the number of negative numbers in grid.   Example 1: Input: grid = [[4...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Write a program to check whether a given number is an ugly number. Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. Example 1: Input: 6 Output: ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You are given a string text of words that are placed among some number of spaces. Each word consists of one or more lowercase English letters and are separated by at least one...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.At a lemonade stand, each lemonade costs $5.  Customers are standing in a queue to buy from you, and order one at a time (in the order specified by bills). Each customer will ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets mus...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time. Return that integer.   Example 1: Input...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Return the number of permutations of 1 to n so that prime numbers are at prime indices (1-indexed.) (Recall that an integer is prime if and only if it is greater than 1, and c...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given a list of strings words representing an English Dictionary, find the longest word in words that can be built one character at a time by other words in words. If there i...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== .remove(x) This operation removes element x from the set. If element x does not exist, it raises a Ke...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== group() A group() expression returns one or more subgroups of the match. Code >>> import re >>> m = ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== itertools.product() This tool computes the cartesian product of input iterables. It is equivalent to ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of In...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given two sets, A and B. Your job is to find whether set A is a subset of set B. If set A is subs...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Given a list of rational numbers,find their product. Concept The reduce() function applies a function of ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== collections.Counter() A counter is a container that stores elements as dictionary keys, and their coun...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== In this task, we would like for you to appreciate the usefulness of the groupby() function of itertools. Y...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== inner The inner tool returns the inner product of two arrays. import numpy A = numpy.array([0, 1]) ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== A valid email address meets the following criteria: It's composed of a username, domain name, and extensi...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== In Python, a string of text can be aligned left, right and center. .ljust(width) This method returns...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== Calendar Module The calendar module allows you to output calendars and provides additional useful func...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== any() This expression returns True if any element of the iterable is true. If the iterable is empty, i...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== If we want to add a single element to an existing set, we can use the .add() operation. It adds the el...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are asked to ensure that the first and last names of people begin with a capital letter in their passp...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== The included code stub will read an integer, n, from STDIN. Without using any string methods, try to print...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.=====Problem Statement===== We have seen that lists are mutable (they can be changed), and tuples are immutable (they cannot be changed). Let's try to understand this with an...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== So far, we have only heard of Python's powers. Now, we will witness them! Powers or exponents in Pyth...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== dot The dot tool returns the dot product of two arrays. import numpy A = numpy.array([ 1, 2 ]) B = ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== The re.sub() tool (sub stands for substitution) evaluates a pattern and, for each valid match, it calls a ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given an HTML code snippet of N lines. Your task is to detect and print all the HTML tags, attribu...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a string S and width w. Your task is to wrap the string into a paragraph of width w. =====I...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You and Fredrick are good friends. Yesterday, Fredrick received credit cards from ABCD Bank. He wants to ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Given the names and grades for each student in a class of N students, store them in a nested list and prin...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== The NumPy (Numeric Python) package helps us manipulate large arrays and matrices of numeric data. To ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a string S. S contains alphanumeric characters only. Your task is to sort the string S in th...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== Concatenate Two or more arrays can be concatenated together using the concatenate function with a tup...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== itertools.combinations(iterable, r) This tool returns the r length subsequences of elements from the i...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.=====Problem Statement===== An extra day is added to the calendar almost every four years as February 29, and the day is called a leap day. It corrects the calendar for the fa...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given the firstname and lastname of a person on two different lines. Your task is to read them and...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== Exceptions Errors detected during execution are called exceptions. Examples: ZeroDivisionError This e...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== min The tool min returns the minimum value along a given axis. import numpy my_array = numpy.array...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== shape The shape tool gives a tuple of array dimensions and can be used to change the dimensions of an...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given n words. Some words may repeat. For each word, output its number of occurrences. The output ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== Polar coordinates are an alternative way of representing Cartesian coordinates or Complex Numbers. A c...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== A set is an unordered collection of elements without duplicate entries. When printed, iterated or conv...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Given an integer, n, print the following values for each integer i from 1 to n: 1. Decimal 2. Octal 3. Hex...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a set A and n other sets. Your job is to find whether set A is a strict superset of each of ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a positive integer N. Print a numerical triangle of height N - 1 like the one below: 1 22 33...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== sum The sum tool returns the sum of array elements over a given axis. import numpy my_array = numpy...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== One of the built-in functions of Python is divmod, which takes two arguments a and b and returns a tup...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== Transpose We can generate the transposition of an array using the tool numpy.transpose. It will not a...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== mean The mean tool computes the arithmetic mean along the specified axis. import numpy my_array = n...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== itertools.permutations(iterable[, r]) This tool returns successive rlength permutations of elements i...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Given the participants' score sheet for your University Sports Day, you are required to find the runner-up...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== poly The poly tool returns the coefficients of a polynomial with the given sequence of roots. print ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== A newly opened multinational brand has decided to base their company logo on the three most common charact...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a string s consisting only of digits 0-9, commas ,, and dots . Your task is to complete the...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Example===== In Python, a string can be split on a delimiter. Example: >>> a = "this is a string" >>> a = a.split(" ") # a is co...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== .intersection() The .intersection() operator returns the intersection of a set and the set of element...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== zeros The zeros tool returns a new array with a given shape and type filled with 0's. import numpy ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== The provided code stub reads and integer, n, from STDIN. For all non-negative integers i < n, print i^2. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== .union() The .union() operator returns the union of a set and the set of elements in an iterable. Som...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Integers in Python can be as big as the bytes in your machine's memory. There is no limit in size as there...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a string N. Your task is to verify that N is a floating point number. In this task, a valid...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Consider a list (list = []). You can perform the following commands: 1. insert i e: Insert integer e at po...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== ABCXYZ company has up to 100 employees. The company decides to create a unique identification number (UID)...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== collections.deque() A deque is a double-ended queue. It can be used to add or remove elements from bot...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Mr. Anant Asankhya is the manager at the INFINITE hotel. The hotel has an infinite amount of rooms. One f...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== There is an array of n integers. There are also 2 disjoint sets, A and B, each containing m integers. You ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== The provided code stub reads two integers from STDIN, a and b. Add code to print three lines where: The fi...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Mr. Vincent works in a door mat manufacturing company. One day, he designed a new door mat with the follow...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== A valid postal code P have to fullfil both below requirements: 1. P must be a number in the range from 10...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== We have seen the applications of union, intersection, difference and symmetric difference operations, ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== The defaultdict tool is a container in the collections class of Python. It's similar to the usual dictiona...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== HTML Hypertext Markup Language is a standard markup language used for creating World Wide Web pages. ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a positive integer N. Your task is to print a palindromic triangle of size N. For example, ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a function f(X) = X^2. You are also given K lists. The ith list consists of N_i elements. Y...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== collections.OrderedDict An OrderedDict is a dictionary that remembers the order of the keys that were...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a spreadsheet that contains a list of N athletes and their details (such as age, height, wei...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== In this challenge, the user enters a string and a substring. You have to print the number of times that th...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== ABC is a right triangle, 90°, at B. Therefore, ANGLE{ABC} = 90°. Point M is the midpoint of hypotenuse AC....
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== There is a horizontal row of n cubes. The length of each cube is given. You need to create a new vertical ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.=====Problem Statement===== You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa. =====Exa...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== .symmetric_difference() The .symmetric_difference() operator returns a set with all the elements that...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== Python has built-in string validation methods for basic data. It can check if a string is composed of ...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== itertools.combinations_with_replacement(iterable, r) This tool returns length subsequences of element...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== CSS colors are defined using a hexadecimal (HEX) notation for the combination of Red, Green, and Blue colo...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== You are given a string S. Your task is to find out whether is a valid regex or not. =====Input Format====...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Function Descriptions===== .difference() The tool .difference() returns a set with all the elements from the set that are not in...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.=====Problem Statement===== Here is a sample line of code that can be executed in Python: print("Hello, World!") You can just as easi...
user: Generate an executable Python function generated from the given prompt. The function should take stdin as input and print the output. Simply call the function after the definition.Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.We are still with squared integers. Given 4 integers `a, b, c, d` we form the sum of the squares of `a` and `b` and then the sum of the squares of `c` and `d`. We multiply th...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.For this game of `BINGO`, you will receive a single array of 10 numbers from 1 to 26 as an input. Duplicate numbers within the array are possible. Each number corresponds to ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Kate and Michael want to buy a pizza and share it. Depending on the price of the pizza, they are going to divide the costs: * If the pizza is less than €5,- Michael invites K...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.You've arrived at a carnival and head straight for the duck shooting tent. Why wouldn't you? You will be given a set amount of ammo, and an aim rating of between 1 and 0. No ...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.In the world of birding there are four-letter codes for the common names of birds. These codes are created by some simple rules: * If the bird's name has only one word, the c...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Complete the function to determine the number of bits required to convert integer `A` to integer `B` (where `A` and `B` >= 0) The upper limit for `A` and `B` is 2^(16), `int....
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.There's a waiting room with N chairs set in single row. Chairs are consecutively numbered from 1 to N. First is closest to the entrance (which is exit as well). For some rea...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Given an array of arguments, representing system call arguments keys and values, join it into a single, space-delimited string. You don't need to care about the application na...
user: Generate an executable Python function generated from the given prompt. Return the function body without invoking it at the final solution.Pete and his mate Phil are out in the countryside shooting clay pigeons with a shotgun - amazing fun. They decide to have a competition. 3 rounds, 2 shots each. Winner is th...