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