rewritten_intent
stringlengths 4
183
⌀ | intent
stringlengths 11
122
| snippet
stringlengths 2
232
| question_id
int64 1.48k
42.8M
|
---|---|---|---|
empty a list `lst` | empty a list | lst[:] = [] | 1,400,608 |
empty a list `alist` | empty a list | alist[:] = [] | 1,400,608 |
reset index of series `s` | Pandas reset index on series to remove multiindex | s.reset_index(0).reset_index(drop=True) | 18,624,039 |
convert unicode text from list `elems` with index 0 to normal text 'utf-8' | How to convert unicode text to normal text | elems[0].getText().encode('utf-8') | 36,623,789 |
create a list containing the subtraction of each item in list `L` from the item prior to it | Subtracting the current and previous item in a list | [(y - x) for x, y in zip(L, L[1:])] | 4,029,436 |
get value in string `line` matched by regex pattern '\\bLOG_ADDR\\s+(\\S+)' | Cleanest way to get a value from a list element | print(re.search('\\bLOG_ADDR\\s+(\\S+)', line).group(1)) | 32,950,347 |
import all classes from module `some.package` | Importing everything ( * ) dynamically from a module | globals().update(importlib.import_module('some.package').__dict__) | 4,116,061 |
convert a list of characters `['a', 'b', 'c', 'd']` into a string | Convert a list of characters into a string | """""".join(['a', 'b', 'c', 'd']) | 4,481,724 |
Slice `url` with '&' as delimiter to get "http://www.domainname.com/page?CONTENT_ITEM_ID=1234" from url "http://www.domainname.com/page?CONTENT_ITEM_ID=1234¶m2¶m3
" | Slicing URL with Python | url.split('&') | 258,746 |
sort dictionary `d` by key | sort a dictionary by key | od = collections.OrderedDict(sorted(d.items())) | 9,001,509 |
sort a dictionary `d` by key | sort a dictionary by key | OrderedDict(sorted(list(d.items()), key=(lambda t: t[0]))) | 9,001,509 |
Execute a put request to the url `url` | PUT Request to REST API using Python | response = requests.put(url, data=json.dumps(data), headers=headers) | 33,127,636 |
replace everything that is not an alphabet or a digit with '' in 's'. | Python remove anything that is not a letter or number | re.sub('[\\W_]+', '', s) | 6,323,296 |
create a list of aggregation of each element from list `l2` to all elements of list `l1` | Python Nested List Comprehension with two Lists | [(x + y) for x in l2 for y in l1] | 16,568,056 |
convert string `x' to dictionary splitted by `=` using list comprehension | convert string to dict using list comprehension in python | dict([x.split('=') for x in s.split()]) | 1,246,444 |
remove index 2 element from a list `my_list` | Remove object from a list of objects in python | my_list.pop(2) | 9,754,729 |
Delete character "M" from a string `s` using python | How to delete a character from a string using python? | s = s.replace('M', '') | 3,559,559 |
null | How to delete a character from a string using python? | newstr = oldstr.replace('M', '') | 3,559,559 |
get the sum of the products of each pair of corresponding elements in lists `a` and `b` | How can I sum the product of two list items using for loop in python? | sum(x * y for x, y in zip(a, b)) | 41,821,112 |
sum the products of each two elements at the same index of list `a` and list `b` | How can I sum the product of two list items using for loop in python? | list(x * y for x, y in list(zip(a, b))) | 41,821,112 |
sum the product of each two items at the same index of list `a` and list `b` | How can I sum the product of two list items using for loop in python? | sum(i * j for i, j in zip(a, b)) | 41,821,112 |
sum the product of elements of two lists named `a` and `b` | How can I sum the product of two list items using for loop in python? | sum(x * y for x, y in list(zip(a, b))) | 41,821,112 |
write the content of file `xxx.mp4` to file `f` | Can I read and write file in one line with Python? | f.write(open('xxx.mp4', 'rb').read()) | 12,426,043 |
Add 1 to each integer value in list `my_list` | How to add an integer to each element in a list? | new_list = [(x + 1) for x in my_list] | 9,304,408 |
get a list of all items in list `j` with values greater than `5` | Return list of items in list greater than some value | [x for x in j if x >= 5] | 4,587,915 |
set color marker styles `--bo` in matplotlib | matplotlib: Set markers for individual points on a line | plt.plot(list(range(10)), '--bo') | 8,409,095 |
set circle markers on plot for individual points defined in list `[1,2,3,4,5,6,7,8,9,10]` created by range(10) | matplotlib: Set markers for individual points on a line | plt.plot(list(range(10)), linestyle='--', marker='o', color='b') | 8,409,095 |
split strings in list `l` on the first occurring tab `\t` and enter only the first resulting substring in a new list | split elements of a list in python | [i.split('\t', 1)[0] for i in l] | 6,696,027 |
Split each string in list `myList` on the tab character | split elements of a list in python | myList = [i.split('\t')[0] for i in myList] | 6,696,027 |
Sum numbers in a list 'your_list' | Summing elements in a list | sum(your_list) | 11,344,827 |
attach debugger pdb to class `ForkedPdb` | How to attach debugger to a python subproccess? | ForkedPdb().set_trace() | 4,716,533 |
Compose keys from dictionary `d1` with respective values in dictionary `d2` | Python: comprehension to compose two dictionaries | result = {k: d2.get(v) for k, v in list(d1.items())} | 17,846,545 |
add one day and three hours to the present time from datetime.now() | datetime.datetime.now() + 1 | datetime.datetime.now() + datetime.timedelta(days=1, hours=3) | 6,310,475 |
null | Convert binary string to list of integers using Python | [int(s[i:i + 3], 2) for i in range(0, len(s), 3)] | 1,386,811 |
switch keys and values in a dictionary `my_dict` | switching keys and values in a dictionary in python | dict((v, k) for k, v in my_dict.items()) | 8,305,518 |
sort a list `L` by number after second '.' | Specific sort a list of numbers separated by dots | print(sorted(L, key=lambda x: int(x.split('.')[2]))) | 21,361,604 |
Check if the value of the key "name" is "Test" in a list of dictionaries `label` | How to find a value in a list of python dictionaries? | any(d['name'] == 'Test' for d in label) | 17,149,561 |
remove all instances of [1, 1] from list `a` | How can I remove all instances of an element from a list in Python? | a[:] = [x for x in a if x != [1, 1]] | 2,186,656 |
remove all instances of `[1, 1]` from a list `a` | How can I remove all instances of an element from a list in Python? | [x for x in a if x != [1, 1]] | 2,186,656 |
convert a list 'a' to a dictionary where each even element represents the key to the dictionary, and the following odd element is the value | Convert a list to a dictionary in Python | b = {a[i]: a[i + 1] for i in range(0, len(a), 2)} | 4,576,115 |
check whether elements in list `a` appear only once | How to check whether elements appears in the list only once in python? | len(set(a)) == len(a) | 3,899,782 |
Generate MD5 checksum of file in the path `full_path` in hashlib | Generating an MD5 checksum of a file | print(hashlib.md5(open(full_path, 'rb').read()).hexdigest()) | 3,431,825 |
null | How to sort a dictionary in python by value when the value is a list and I want to sort it by the first index of that list | sorted(list(data.items()), key=lambda x: x[1][0]) | 42,765,620 |
randomly switch letters' cases in string `s` | Pythons fastest way of randomising case of a string | """""".join(x.upper() if random.randint(0, 1) else x for x in s) | 8,344,905 |
force bash interpreter '/bin/bash' to be used instead of shell | How to force os.system() to use bash instead of shell | os.system('GREPDB="echo 123"; /bin/bash -c "$GREPDB"') | 21,822,054 |
Run a command `echo hello world` in bash instead of shell | How to force os.system() to use bash instead of shell | os.system('/bin/bash -c "echo hello world"') | 21,822,054 |
access the class variable `a_string` from a class object `test` | how to access the class variable by string in Python? | getattr(test, a_string) | 13,303,100 |
Display a image file `pathToFile` | How to display a jpg file in Python? | Image.open('pathToFile').show() | 5,333,244 |
replace single quote character in string "didn't" with empty string '' | Replace the single quote (') character from a string | """didn't""".replace("'", '') | 3,151,146 |
sort list `files` based on variable `file_number` | Sorting files in a list | files.sort(key=file_number) | 9,466,017 |
remove all whitespace in a string `sentence` | remove all whitespace in a string | sentence.replace(' ', '') | 8,270,092 |
remove all whitespace in a string `sentence` | remove all whitespace in a string | pattern = re.compile('\\s+')
sentence = re.sub(pattern, '', sentence) | 8,270,092 |
remove whitespace in string `sentence` from beginning and end | remove all whitespace in a string | sentence.strip() | 8,270,092 |
remove all whitespaces in string `sentence` | remove all whitespace in a string | sentence = re.sub('\\s+', '', sentence, flags=re.UNICODE) | 8,270,092 |
remove all whitespaces in a string `sentence` | remove all whitespace in a string | sentence = ''.join(sentence.split()) | 8,270,092 |
sum all the values in a counter variable `my_counter` | Sum all values of a counter in Python | sum(my_counter.values()) | 32,511,444 |
find the euclidean distance between two 3-d arrays `A` and `B` | Numpy: find the euclidean distance between two 3-D arrays | np.sqrt(((A - B) ** 2).sum(-1)) | 40,319,433 |
create list `levels` containing 3 empty dictionaries | Python: define multiple variables of same type? | levels = [{}, {}, {}] | 4,411,811 |
find the sums of length 7 subsets of a list `daily` | Find the sum of subsets of a list in python | weekly = [sum(visitors[x:x + 7]) for x in range(0, len(daily), 7)] | 6,133,434 |
Delete an element `key` from a dictionary `d` | Delete an element from a dictionary | del d[key] | 5,844,672 |
Delete an element 0 from a dictionary `a` | Delete an element from a dictionary | {i: a[i] for i in a if (i != 0)} | 5,844,672 |
Delete an element "hello" from a dictionary `lol` | Delete an element from a dictionary | lol.pop('hello') | 5,844,672 |
Delete an element with key `key` dictionary `r` | Delete an element from a dictionary | del r[key] | 5,844,672 |
solve for the least squares' solution of matrices `a` and `b` | Efficient computation of the least-squares algorithm in NumPy | np.linalg.solve(np.dot(a.T, a), np.dot(a.T, b)) | 41,648,246 |
split dictionary/list inside a pandas column 'b' into separate columns in dataframe `df` | Splitting dictionary/list inside a Pandas Column into Separate Columns | pd.concat([df.drop('b', axis=1), pd.DataFrame(df['b'].tolist())], axis=1) | 38,231,591 |
loop through 0 to 10 with step 2 | loop through a Python list by twos | for i in range(0, 10, 2):
pass | 2,990,121 |
loop through `mylist` with step 2 | loop through a Python list by twos | for i in mylist[::2]:
pass | 2,990,121 |
lowercase string values with key 'content' in a list of dictionaries `messages` | How to use map to lowercase strings in a dictionary? | [{'content': x['content'].lower()} for x in messages] | 42,353,686 |
convert a list `my_list` into string with values separated by spaces | convert list into string with spaces in python | """ """.join(my_list) | 12,309,976 |
replace each occurrence of the pattern '(http://\\S+|\\S*[^\\w\\s]\\S*)' within `a` with '' | Regex. Match words that contain special characters or 'http://' | re.sub('(http://\\S+|\\S*[^\\w\\s]\\S*)', '', a) | 4,695,143 |
check if string `str` is palindrome | How to check for palindrome using Python logic | str(n) == str(n)[::-1] | 17,331,290 |
upload binary file `myfile.txt` with ftplib | How to upload binary file with ftplib in Python? | ftp.storbinary('STOR myfile.txt', open('myfile.txt', 'rb')) | 2,911,754 |
remove all characters from string `stri` upto character 'I' | How to remove all characters before a specific character in Python? | re.sub('.*I', 'I', stri) | 30,945,784 |
parse a comma-separated string number '1,000,000' into int | Python parse comma-separated number into int | int('1,000,000'.replace(',', '')) | 2,953,746 |
combine dataframe `df1` and dataframe `df2` by index number | Combine two Pandas dataframes with the same index | pd.merge(df1, df2, left_index=True, right_index=True, how='outer') | 28,773,683 |
null | Combine two Pandas dataframes with the same index | pandas.concat([df1, df2], axis=1) | 28,773,683 |
check if all boolean values in a python dictionary `dict` are true | What's the best way to aggregate the boolean values of a Python dictionary? | all(dict.values()) | 2,806,611 |
use regex pattern '^12(?=.{4}$)' to remove digit 12 if followed by 4 other digits in column `c_contofficeID` of dataframe `df` | How to extract first two characters from string using regex | df.c_contofficeID.str.replace('^12(?=.{4}$)', '') | 40,273,313 |
reverse a list `L` | reverse a list | L[::(-1)] | 3,940,128 |
reverse a list `array` | reverse a list | reversed(array) | 3,940,128 |
reverse a list `L` | reverse a list | L.reverse() | 3,940,128 |
reverse a list `array` | reverse a list | list(reversed(array)) | 3,940,128 |
get first element of each tuple in list `A` | How to index nested lists in Python? | [tup[0] for tup in A] | 31,302,904 |
replace character 'a' with character 'e' and character 's' with character '3' in file `contents` | Replacing characters in a file | newcontents = contents.replace('a', 'e').replace('s', '3') | 10,562,778 |
serialise SqlAlchemy RowProxy object `row` to a json object | How to serialize SqlAlchemy result to JSON? | json.dumps([dict(list(row.items())) for row in rs]) | 5,022,066 |
get file '~/foo.ini' | Cross-platform addressing of the config file | config_file = os.path.expanduser('~/foo.ini') | 3,227,624 |
get multiple parameters with same name from a url in pylons | How to get multiple parameters with same name from a URL in Pylons? | request.params.getall('c') | 14,734,750 |
Convert array `x` into a correlation matrix | how to create similarity matrix in numpy python? | np.corrcoef(x) | 18,432,823 |
Find the greatest number in set `(1, 2, 3)` | Python - Find the greatest number in a set of numbers | print(max(1, 2, 3)) | 3,090,175 |
Retrieve parameter 'var_name' from a GET request. | Google App Engine - Request class query_string | self.request.get('var_name') | 1,391,026 |
Add 100 to each element of column "x" in dataframe `a` | python pandas: apply a function with arguments to a series. Update | a['x'].apply(lambda x, y: x + y, args=(100,)) | 21,188,504 |
Django get first 10 records of model `User` ordered by criteria 'age' of model 'pet' | Get models ordered by an attribute that belongs to its OneToOne model | User.objects.order_by('-pet__age')[:10] | 40,079,728 |
delay for "5" seconds | make a time delay | time.sleep(5) | 510,348 |
make a 60 seconds time delay | make a time delay | time.sleep(60) | 510,348 |
make a 0.1 seconds time delay | make a time delay | sleep(0.1) | 510,348 |
make a 60 seconds time delay | make a time delay | time.sleep(60) | 510,348 |
make a 0.1 seconds time delay | make a time delay | time.sleep(0.1) | 510,348 |
From a list of strings `my_list`, remove the values that contains numbers. | Remove strings from a list that contains numbers in python | [x for x in my_list if not any(c.isdigit() for c in x)] | 16,084,642 |
get the middle two characters of a string 'state' in a pandas dataframe `df` | how to do a left,right and mid of a string in a pandas dataframe | df['state'].apply(lambda x: x[len(x) / 2 - 1:len(x) / 2 + 1]) | 20,970,279 |
draw a grid line on every tick of plot `plt` | How do I draw a grid onto a plot in Python? | plt.grid(True) | 8,209,568 |