question_id
int64 104k
42.1M
| parent_answer_post_id
int64 104k
42.1M
| prob
float64 0.23
0.87
| snippet
stringlengths 7
76
| intent
stringlengths 19
108
| id
stringlengths 15
19
| rewritten_intent
stringlengths 27
199
|
---|---|---|---|---|---|---|
34,705,205 | 34,705,233 | 0.869 | sorted(l, key=lambda x: (-int(x[1]), x[0])) | Sort a nested list by two elements | 34705205_34705233_0 | Sort a list l of tuples. Each tuple has 2 elements, and the sorting is done with respect to the second one and from the greatest to the lowest value. |
13,905,936 | 13,905,946 | 0.85267 | [int(x) for x in str(num)] | converting integer to list in python | 13905936_13905946_0 | convert an integer num into a list of string digits |
13,837,848 | 13,838,041 | 0.852143 | c.decode('unicode_escape') | Converting byte string in unicode string | 13837848_13838041_0 | convert a byte string c into an unicode string |
861,190 | 861,238 | 0.815429 | mylist.sort(key=lambda d: (d['weight'], d['factor'])) | Ordering a list of dictionaries in python | 861190_861238_0 | sort a list of dictionaries with respect to the keys 'weigth' and 'factor'. |
33,361,446 | 33,361,777 | 0.807073 | print([l[i:i + n] for i in range(len(l)) for n in range(1, len(l) - i + 1)]) | Two Combination Lists from One List | 33361446_33361777_0 | print a list of all the sublists of a list l. |
9,775,731 | 9,775,761 | 0.797127 | max(min(my_value, max_value), min_value) | Clamping floating numbers in Python? | 9775731_9775761_0 | Return the value of a number my_value clipped between min_value and max_value |
15,886,340 | 15,886,375 | 0.793709 | re.sub('[^A-Z]', '', s) | How to extract all UPPER from a string? Python | 15886340_15886375_0 | regex to remove all the upper case characters in a string s |
25,040,875 | 25,040,901 | 0.789484 | [d['key'] for d in l] | Get a list of values from a list of dictionaries in python | 25040875_25040901_0 | For a list of dictionaries l, write a code snippet to return the list of values associated to the key 'key' for each of its element. |
3,308,102 | 3,308,117 | 0.786179 | [x[1] for x in elements] | How to extract the n-th elements from a list of tuples in python? | 3308102_3308117_0 | Extract the list of second elements from a list of tuples elements |
652,291 | 652,347 | 0.775528 | list.sort(key=lambda item: item['date'], reverse=True) | sorting a list of dictionary values by date in python | 652291_652347_0 | Reverse sort a list of dictionary list with respect to the value of the key 'date'. |
4,111,412 | 4,111,417 | 0.77544 | [i for i, e in enumerate(a) if e != 0] | How do I get a list of indices of non zero elements in a list? | 4111412_4111417_0 | Get the list of indices of non zero elements in the list a |
4,287,209 | 4,287,233 | 0.774941 | sorted(the_list, key=lambda x: int(x.split('_')[1])) | Sort list of strings by integer suffix in python | 4287209_4287233_0 | Sort a list of strings the_list with respect to the value of the suffix after the character '_' |
41,067,960 | 41,067,989 | 0.739221 | r = int(''.join(map(str, x))) | How to convert a list of multiple integers into a single integer? | 41067960_41067989_0 | Convert a list of integers x into a string r |
34,962,104 | 34,962,199 | 0.735729 | df['a'] = df['a'].apply(lambda x: x + 1) | Pandas: How can I use the apply() function for a single column? | 34962104_34962199_0 | Use the function apply to increment the values of the column 'a' of a pandas DataFrame df |
3,494,906 | 3,495,395 | 0.73437 | {k: v for d in L for k, v in list(d.items())} | How do I merge a list of dicts into a single dict? | 3494906_3495395_0 | Merge a list of dictionaries L into a single dictionary |
12,814,667 | 12,814,719 | 0.733883 | a.sort(key=lambda x: b.index(x)) | How to sort a list according to another list? | 12814667_12814719_0 | Sort a list of elements a with respect to the index in a list b |
7,996,940 | 7,997,011 | 0.732512 | li1.sort(key=lambda x: not x.startswith('b.')) | What is the best way to sort list with custom sorting parameters in Python? | 7996940_7997011_0 | Sort a list of strings li1 such that those starting with 'b.' come first. |
2,508,861 | 2,508,940 | 0.731841 | int(num) | Python: Convert a string to an integer | 2508861_2508940_0 | convert a string num into an integer |
1,386,811 | 1,386,828 | 0.728649 | [int(s[i:i + 3], 2) for i in range(0, len(s), 3)] | Convert binary string to list of integers using Python | 1386811_1386828_0 | Given a binary string s, divide it into blocks of size 3 and return a list containing the decimal value corresponding to each block. |
6,294,179 | 6,294,205 | 0.727966 | indices = [i for i, x in enumerate(my_list) if x == 'whatever'] | How to find all occurrences of an element in a list? | 6294179_6294205_0 | Given a list of string s, build the list of indices corresponding to the string 'whatever'. |
16,772,071 | 16,772,088 | 0.726468 | sorted(list(data.items()), key=lambda x: x[1]) | sort dict by value python | 16772071_16772088_0 | Sort the items of the dictionary data by value |
28,161,356 | 28,161,433 | 0.723997 | df.sort_values(by='Date') | Sort Pandas Dataframe by Date | 28161356_28161433_0 | Sort a DataFrame df by the value of the column 'Date' |
29,360,607 | 29,360,674 | 0.722502 | print(' '.join(set(s))) | How does this function to remove duplicate characters from a string in python work? | 29360607_29360674_0 | print the string obtained by removing all the duplicate in a string s. |
11,791,568 | 11,791,601 | 0.717945 | [x for x in my_list if not x.startswith('#')] | What is the most pythonic way to exclude elements of a list that start with a specific character? | 11791568_11791601_0 | Remove the elements that start with '#' in the list my_list. |
3,559,559 | 3,559,600 | 0.714482 | newstr = oldstr.replace('M', '') | How to delete a character from a string using python? | 3559559_3559600_0 | Delete all the occurrence of the character 'M' in oldstr and store the result in the variable newstr. |
4,880,960 | 4,880,971 | 0.701062 | sum(d.values()) | Sum of all values in a Python dict | 4880960_4880971_0 | Sum all the values of a python dict d |
28,773,683 | 28,773,733 | 0.698927 | pandas.concat([df1, df2], axis=1) | Combine two Pandas dataframes with the same index | 28773683_28773733_0 | Combine 2 pandas dataframes df1 and df2 with the same index. |
35,582,959 | 35,582,986 | 0.698902 | list(s) | How do I convert user input into a list? | 35582959_35582986_0 | Convert a string s into a list of characters. |
1,094,717 | 1,094,721 | 0.698366 | int(s.split('.')[0]) | Convert a string to integer with decimal in Python | 1094717_1094721_0 | Convert a string s representing representing a decimal number to an integer. |
2,191,699 | 2,191,712 | 0.697555 | [(x, y) for x, y in a if x == 1] | Find an element in a list of tuples | 2191699_2191712_0 | Given a list of 2D tuples a, return the list of tuples for whom the first element is equal to 1. |
6,890,170 | 6,890,255 | 0.696187 | len(li) - 1 - li[::-1].index('a') | How to find the last occurrence of an item in a Python list | 6890170_6890255_0 | Find the index of the last occurrence of 'a' in the string li. |
2,587,402 | 2,587,419 | 0.695257 | xs.sort(key=lambda s: len(s)) | Sorting Python list based on the length of the string | 2587402_2587419_0 | Sort a list of strings xs based on the length. |
22,240,602 | 22,240,612 | 0.69463 | len(set(mylist)) == 1 | How do I check if all elements in a list are the same? | 22240602_22240612_0 | Check if all the elements of the list mylist are the same. |
21,669,374 | 21,669,393 | 0.69411 | hex(ord(c)) | convert string to hex in python | 21669374_21669393_0 | Convert the char c into hex |
22,749,706 | 22,749,723 | 0.692178 | [len(x) for x in s.split()] | How to get the length of words in a sentence? | 22749706_22749723_0 | Get the length of each word in a sentence s |
674,519 | 674,536 | 0.688835 | [(k, v) for k, v in a.items()] | How can I convert a Python dictionary to a list of tuples? | 674519_674536_0 | Convert a Python dictionary a into a list of tuples |
8,556,076 | 8,556,080 | 0.684711 | my_list[-10:] | Python - How to extract the last x elements from a list | 8556076_8556080_0 | Extract the last 10 elements of the python list my_list |
104,420 | 104,471 | 0.674376 | itertools.permutations(s) | How to generate all permutations of a list in Python | 104420_104471_0 | Get all the permutations of a list s in python. |
11,344,827 | 11,344,839 | 0.668318 | sum(your_list) | Summing elements in a list | 11344827_11344839_0 | Sum elements of a list your_list |
23,748,995 | 23,749,057 | 0.666899 | df['a'].tolist() | Pandas DataFrame to list | 23748995_23749057_0 | Return the values of the column 'a' of the pandas DataFrame df into a list |
42,125,131 | 42,125,197 | 0.664192 | df.dropna(subset=['city', 'latitude', 'longitude'], how='all') | Delete row based on nulls in certain columns (pandas) | 42125131_42125197_0 | Delete null in the columns 'city', 'longitude' and 'latitude' of the dataframe df. |
14,743,454 | 14,743,473 | 0.64028 | [k for k, v in dictA.items() if v.count('duck') > 1] | Counting values in dictionary | 14743454_14743473_0 | Given a dictionary dictA return the list of keys whose values contain at least 2 occurrences of 'duck' |
26,894,227 | 26,894,268 | 0.647453 | sum(map(lambda x: x * x, l)) | sum of squares in a list in one line? | 26894227_26894268_0 | Sum of squares in the list l |
13,252,333 | 13,252,348 | 0.626962 | all(isinstance(x, int) for x in lst) | Python check if all elements of a list are the same type | 13252333_13252348_1 | Check if all elements of a list lst are of type int. |
4,843,173 | 4,843,178 | 0.616813 | isinstance(s, str) | How to check if type of a variable is string? | 4843173_4843178_0 | Check if a variable s is a string. |
5,864,485 | 5,864,507 | 0.614176 | mystring.split(',') | How can I split this comma-delimited string in Python? | 5864485_5864507_0 | Split the string mystring by comma |
18,256,363 | 18,256,476 | 0.613056 | f = open('example.txt', 'r') | How do I print the content of a .txt file in Python? | 18256363_18256476_1 | Read a .txt file example.txt and store it into the variable f |
32,490,629 | 32,490,661 | 0.749688 | datetime.datetime.today().strftime('%Y-%m-%d') | Getting today's date in YYYY-MM-DD in Python? | 32490629_32490661_0 | Getting today's date in YYYY-MM-DD in Python with datetime |
19,779,790 | 19,779,811 | 0.739086 | datetime.datetime.now() - datetime.timedelta(days=1) | How to get yesterday in python | 19779790_19779811_0 | How to get yesterday's data in python with datetime? |
521,502 | 521,510 | 0.729452 | instance.__class__.__name__ | How to get the concrete class name as a string? | 521502_521510_0 | Given an object named instance of a given class, get the class name as a string |
3,428,769 | 3,428,785 | 0.704297 | max(abs(x - y) for x, y in zip(values[1:], values[:-1])) | Finding the largest delta between two integers in a list in python | 3428769_3428785_0 | Find the largest delta between two integers in the list values in python |
18,574,108 | 18,579,083 | 0.702526 | df.to_xml('foo.xml') | How do convert a pandas/dataframe to XML? | 18574108_18579083_0 | Save the content of the pandas dataframe df into a file 'foo.xml'. |
3,739,909 | 3,739,939 | 0.651989 | s.replace(' ', '') | How to strip all whitespace from string | 3739909_3739939_0 | Strip all whitespace from a string s |
5,245,058 | 5,245,216 | 0.648501 | [line for line in open('text.txt') if 'apple' in line] | Python: Filter lines from a text file which contain a particular word | 5245058_5245216_0 | read the file 'text.txt' and store all the lines which contain the word 'apple' in a list. |
28,538,536 | 37,069,701 | 0.635862 | df.drop(['col1', 'col2'], axis=1, inplace=True) | Deleting mulitple columns in Pandas | 28538536_37069701_0 | Delete columns 'col1' and 'col2' from pandas dataframe df. |
3,419,082 | 3,419,189 | 0.61457 | np.savetxt('test.txt', data) | Write multiple numpy arrays to file | 3419082_3419189_0 | Save the numpy array data into a file 'test.txt'. |
15,752,422 | 15,752,582 | 0.605945 | df.set_index('month') | Python Pandas - Date Column to Column index | 15752422_15752582_0 | Find common elements to 2 lists x and y. |
38,708,621 | 38,709,042 | 0.589873 | np.isnan(a).sum() | How to calculate percentage of sparsity for a numpy array/matrix? | 38708621_38709042_0 | Find the number of NaN values in a numpy array a. |
2,759,323 | 2,759,331 | 0.586185 | os.listdir(path) | How can I list the contents of a directory in Python? | 2759323_2759331_0 | List the content of a directory given its path path. |
6,490,560 | 6,490,586 | 0.50547 | a = a[-1:] + a[:-1] | How do I move the last item in a list to the front in python? | 6490560_6490586_0 | Move the last item of the list a to the front in python |
11,764,260 | 11,764,285 | 0.62482 | arr[arr != 0].min() | How to find the minimum value in a numpy matrix? | 11764260_11764285_0 | Minimum non zero element in the numpy matrix arr |
12,791,501 | 12,791,510 | 0.618933 | x = [[] for i in range(3)] | Python initializing a list of lists | 12791501_12791510_0 | Create an list of 3 empty lists and store it in the variable x |
14,352,621 | 14,352,657 | 0.450046 | set(a).intersection(b) | compare if an element exists in two lists | 14352621_14352657_0 | Find the set of elements that are common to two lists a and b |
32,030,343 | 32,030,456 | 0.432476 | Y = X - X.mean(axis=1).reshape(-1, 1) | subtracting the mean of each row in numpy with broadcasting | 32030343_32030456_0 | Subtract the mean of each row from a numpy array X with broadcasting and store the result in a matrix Y. |
15,715,912 | 15,716,103 | 0.431923 | del l[-n:] | Remove the last N elements of a list | 15715912_15716103_0 | Delete the last n elements of a list l |
6,490,560 | 6,490,608 | 0.428106 | a.insert(0, a.pop()) | How do I move the last item in a list to the front in python? | 6490560_6490608_0 | Given a python list a, move its last item to the front. |
2,294,493 | 2,294,510 | 0.364759 | s.find('r') | How to get the position of a character in Python? | 2294493_2294510_0 | Find the position of the character 'r' in the string s. |
4,945,548 | 4,945,558 | 0.355587 | print(s[1:]) | Remove the first character of a string | 4945548_4945558_0 | print the string s but ommit the first character. |
9,595,135 | 9,595,161 | 0.354152 | math.sqrt(x) | How to calc square root in python? | 9595135_9595161_0 | compute the square root of x by using the module math. |
12,491,537 | 12,491,575 | 0.339451 | [s[i:i + 2] for i in range(0, len(s), 2)] | Splitting a string into 2-letter segments | 12491537_12491575_0 | Split the string s into a list of 2-letter segments with contiguous letters. |
3,392,354 | 31,972,583 | 0.329498 | a = set() | python: append values to a set | 3392354_31972583_1 | Create a variable a and initialize it as an empty set. |
1,724,473 | 1,724,485 | 0.314704 | chr(ord('a') + i) | How could I print out the nth letter of the alphabet in Python? | 1724473_1724485_0 | Given an index i such that 0 <= i < 26, how to find the letter of the alphabet with that index? |
16,202,348 | 16,202,486 | 0.305187 | e / e.sum(axis=1, keepdims=True) | numpy divide row by row sum | 16202348_16202486_0 | Divide each row of a numpy array e by the row's sum. |
448,837 | 448,901 | 0.305181 | print('Hello, world!') | How do I create a webpage with buttons that invoke various Python scripts on the system serving the webpage? | 448837_448901_0 | Print 'Hello, world' in python. |
6,789,927 | 9,262,736 | 0.288494 | numpy.linalg.lstsq(a, b) | Is there a python module to solve linear equations? | 6789927_9262736_0 | Use numpy to computes the vector x that solves the equation ax = b |
11,125,429 | 11,125,452 | 0.288242 | a.shape | size of NumPy array | 11125429_11125452_0 | Get the shape of a numpy array a. |
9,819,602 | 9,819,617 | 0.287713 | dict(y, **x) | Union of dict objects in Python | 9819602_9819617_1 | Merge 2 dictionnaries x and y. |
40,034,993 | 40,035,266 | 0.280603 | np.multiply(a, b) | How to get element-wise matrix multiplication (Hadamard product) in numpy? | 40034993_40035266_1 | Write the element-wise matrix multiplication (Hadamard product) of 2 numpy arrays a and b. |
2,050,637 | 2,050,649 | 0.276625 | (s + mystring for s in mylist) | Appending the same string to a list of strings in Python | 2050637_2050649_1 | Given a list of strings stored as the variable mylist, append to each of its element the string mystring. |
14,471,177 | 14,471,204 | 0.264702 | s[-1].isdigit() | Python - Check if the last characters in a string are numbers | 14471177_14471204_0 | Check is the last element of the string s is a digit. |
6,444,548 | 34,704,661 | 0.264574 | width, height = img.size | How do I get the picture size with PIL? | 6444548_34704661_1 | Get the width and the height of the image image with the help of PIL. |
20,309,255 | 20,309,271 | 0.262348 | name += ' ' * (length - len(name)) | How to pad a string to a fixed length with spaces in Python? | 20309255_20309271_0 | Pad the string name to length with spaces in Python. |
12,555,443 | 12,555,492 | 0.230541 | def square(arr):
return [(i ** 2) for i in arr] | Squaring all elements in a list | 12555443_12555492_2 | Write a function square_list which takes a list arr as argument and return the list obtained by squaring each of its elements. |
473,099 | 473,108 | 0.229305 | try :
my_dict[k] += 1
except :
my_dict[k] = 1 | Check if a given key already exists in a dictionary and increment it | 473099_473108_0 | Given a dictionary my_dict, increment of the value of the key k if it exists. Otherwise set it to 1. |
6,072,470 | 6,072,496 | 0.229009 | d = dict(l) | Creating a Dictionary from a List of 2-Tuples | 6072470_6072496_0 | Create a dictionary d from a list of 2-Tuples l. |
14,661,051 | 14,661,482 | 0.239257 | json.dumps(my_dict) | Convert Python dictionary to JSON array | 14661051_14661482_1 | Convert the python dictionary my_dict to a JSON array. |
20,297,332 | 20,297,639 | 0.250113 | len(df.columns) | Python pandas dataframe: retrieve number of columns | 20297332_20297639_0 | Get the number of columns of a pandas dataframe df. |
32,109,319 | 32,109,519 | 0.310411 | (np.abs(x) + x) / 2 | How to implement the ReLU function in Numpy | 32109319_32109519_0 | How to compute ReLU(x) where x is a numpy array? |
40,587,251 | 40,587,319 | 0.713835 | scipy.sparse.csr_matrix([column['rating'], column['user'], column['movie']]) | How to create a ratings csr_matrix in scipy? | 40587251_40587319_0 | You are given a pandas dataframe column. Use scipy to build a csr_matrix out of the columns 'rating', 'user' and 'movie'. |
1,456,617 | 1,456,645 | 0.709862 | print(random.choice(words)) | Return a random word from a word list in python | 1456617_1456645_0 | Given a list of string words, choose randomly one of them by using the module random in python. |
27,905,295 | 27,905,350 | 0.709486 | df.fillna(method='ffill', inplace=True) | How to replace NaNs by preceding values in pandas DataFrame? | 27905295_27905350_0 | Replace NaNs in the pandas dataframe df by using preceding values. Do it in place. |
18,574,108 | 18,579,083 | 0.702526 | df.to_xml('foo.xml') | How do convert a pandas/dataframe to XML? | 18574108_18579083_0 | Save the pandas dataframe df in a xml file 'foo.xml'. |
14,688,391 | 14,693,358 | 0.675455 | X_train = scaler.fit(X_train).transform(X_train) | How to apply standardization to SVMs in scikit-learn? | 14688391_14693358_0 | With scikit-learn you have an variable scaler that is a StandardScaler, used it to apply standardization to the matrix X_train. |
23,748,995 | 23,749,057 | 0.666899 | df['a'].tolist() | Pandas DataFrame to list | 23748995_23749057_0 | Convert the column 'a' of the pandas dataframe df to a python list. |
41,821,112 | 41,821,169 | 0.665838 | sum(x * y for x, y in list(zip(a, b))) | How can I sum the product of two list items using for loop in python? | 41821112_41821169_0 | Sum the product of 2 list items x and y which have the same length. |
5,349,570 | 5,349,616 | 0.479303 | numpy.prod(a) | How can I get the product of all elements in a one dimensional numpy array | 5349570_5349616_0 | Get the product of all elements in a one dimensional numpy array a. |
5,228,383 | 5,228,392 | 0.479089 | dist = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2) | How do I find the distance between two points? | 5228383_5228392_0 | You have 2 points (x1, y1) and (x2, y2) in 2D, compute the distance between them. |
12,246,680 | 12,246,720 | 0.424306 | np.hstack([X, Y]) | joining two numpy matrices | 12246680_12246720_0 | Merge two numpy arrays X and Y horizontally. |
20,459,536 | 20,459,839 | 0.397245 | scipy.sparse.csr_matrix(df.values) | Convert Pandas dataframe to Sparse Numpy Matrix directly | 20459536_20459839_0 | Convert pandas dataframe df to scipy sparse matrix. |
29,774,964 | 29,776,004 | 0.390449 | max(n for n in range(1000) if str(n) == str(n)[::-1] and is_prime(n)) | Max Prime Palindrome in Python | 29774964_29776004_0 | You are provided with a function is_prime which takes a number as input and return True if it is prime and False otherwise. Return the biggest number < 1000 which is a prime numnber and a palindrome. |
- Downloads last month
- 40