question_id
stringlengths
7
12
nl
stringlengths
4
200
cmd
stringlengths
2
232
oracle_man
sequence
canonical_cmd
stringlengths
2
228
cmd_name
stringclasses
1 value
14411633-100
do a boolean check if a string `lestring` contains any of the items in list `lelist`
any(e in lestring for e in lelist)
[ "python.library.functions#any" ]
any(e in VAR_STR for e in VAR_STR)
conala
10972410-96
combine two columns `foo` and `bar` in a pandas data frame
pandas.concat([df['foo'].dropna(), df['bar'].dropna()]).reindex_like(df)
[ "pandas.reference.api.pandas.concat", "pandas.reference.api.pandas.index.dropna", "pandas.reference.api.pandas.series.reindex_like" ]
pandas.concat([df['VAR_STR'].dropna(), df['VAR_STR'].dropna()]).reindex_like(df)
conala
10915391-10
sort a list of dictionaries `a` by dictionary values in descending order
sorted(a, key=lambda i: list(i.values())[0], reverse=True)
[ "python.library.functions#sorted", "python.library.functions#list", "python.library.stdtypes#dict.values" ]
sorted(VAR_STR, key=lambda i: list(i.values())[0], reverse=True)
conala
10915391-39
sorting a list of dictionary `a` by values in descending order
sorted(a, key=dict.values, reverse=True)
[ "python.library.functions#sorted" ]
sorted(VAR_STR, key=dict.values, reverse=True)
conala
15210485-43
split string `s` by '@' and get the first element
s.split('@')[0]
[ "python.library.stdtypes#str.split" ]
VAR_STR.split('VAR_STR')[0]
conala
3523048-94
Add a tuple with value `another_choice` to a tuple `my_choices`
final_choices = ((another_choice,) + my_choices)
[]
final_choices = (VAR_STR,) + VAR_STR
conala
3523048-81
Add a tuple with value `another_choice` to a tuple `my_choices`
final_choices = ((another_choice,) + my_choices)
[]
final_choices = (VAR_STR,) + VAR_STR
conala
23286254-50
pair each element in list `it` 3 times into a tuple
zip(it, it, it)
[ "python.library.functions#zip" ]
zip(VAR_STR, VAR_STR, VAR_STR)
conala
19672101-46
store integer 3, 4, 1 and 2 in a list
[3, 4, 1, 2]
[]
[3, 4, 1, 2]
conala
3728017-8
Sorting while preserving order in python
sorted(enumerate(a), key=lambda x: x[1])
[ "python.library.functions#sorted", "python.library.functions#enumerate" ]
sorted(enumerate(a), key=lambda x: x[1])
conala
40498088-80
get list of sums of neighboring integers in string `example`
[sum(map(int, s)) for s in example.split()]
[ "python.library.functions#map", "python.library.functions#sum", "python.library.stdtypes#str.split" ]
[sum(map(int, s)) for s in VAR_STR.split()]
conala
14745022-45
split column 'AB' in dataframe `df` into two columns by first whitespace ' '
df['AB'].str.split(' ', 1, expand=True)
[ "python.library.stdtypes#str.split" ]
VAR_STR['VAR_STR'].str.split(' ', 1, expand=True)
conala
14745022-49
pandas dataframe, how do i split a column 'AB' into two 'A' and 'B' on delimiter ' '
df['A'], df['B'] = df['AB'].str.split(' ', 1).str
[ "python.library.stdtypes#str.split" ]
df['VAR_STR'], df['VAR_STR'] = df['VAR_STR'].str.split(' ', 1).str
conala
14734750-16
get multiple parameters with same name from a url in pylons
request.params.getall('c')
[]
request.params.getall('c')
conala
2637760-10
match contents of an element to 'Example' in xpath (lxml)
tree.xpath(".//a[text()='Example']")[0].tag
[]
tree.xpath(".//a[text()='Example']")[0].tag
conala
36381230-4
find rows of 2d array in 3d numpy array 'arr' if the row has value '[[0, 3], [3, 0]]'
np.argwhere(np.all(arr == [[0, 3], [3, 0]], axis=(1, 2)))
[ "numpy.reference.generated.numpy.argwhere", "numpy.reference.generated.numpy.all" ]
np.argwhere(np.all(VAR_STR == [VAR_STR], axis=(1, 2)))
conala
14524322-31
How to convert a date string '2013-1-25' in format '%Y-%m-%d' to different format '%m/%d/%y'
datetime.datetime.strptime('2013-1-25', '%Y-%m-%d').strftime('%m/%d/%y')
[ "python.library.datetime#datetime.datetime.strptime", "python.library.datetime#datetime.datetime.strftime" ]
datetime.datetime.strptime('VAR_STR', 'VAR_STR').strftime('VAR_STR')
conala
14524322-31
convert a date string '2013-1-25' in format '%Y-%m-%d' to different format '%-m/%d/%y'
datetime.datetime.strptime('2013-1-25', '%Y-%m-%d').strftime('%-m/%d/%y')
[ "python.library.datetime#datetime.datetime.strptime", "python.library.datetime#datetime.datetime.strftime" ]
datetime.datetime.strptime('VAR_STR', 'VAR_STR').strftime('VAR_STR')
conala
11300383-68
find the count of a word 'Hello' in a string `input_string`
input_string.count('Hello')
[ "python.library.stdtypes#str.count" ]
VAR_STR.count('VAR_STR')
conala
42178481-4
count the number of trailing question marks in string `my_text`
len(my_text) - len(my_text.rstrip('?'))
[ "python.library.functions#len", "python.library.stdtypes#str.rstrip" ]
len(VAR_STR) - len(VAR_STR.rstrip('?'))
conala
7900882-78
extract dictionary `d` from list `a` where the value associated with the key 'name' of dictionary `d` is equal to 'pluto'
[d for d in a if d['name'] == 'pluto']
[]
[VAR_STR for VAR_STR in VAR_STR if VAR_STR['VAR_STR'] == 'VAR_STR']
conala
7900882-19
extract dictionary from list of dictionaries based on a key's value.
[d for d in a if d['name'] == 'pluto']
[]
[d for d in a if d['name'] == 'pluto']
conala
7670226-12
get second array column length of array `a`
a.shape[1]
[]
VAR_STR.shape[1]
conala
17134716-54
convert the dataframe column 'col' from string types to datetime types
df['col'] = pd.to_datetime(df['col'])
[ "pandas.reference.api.pandas.to_datetime" ]
df['VAR_STR'] = pd.to_datetime(df['VAR_STR'])
conala
11403474-99
remove all non -word, -whitespace, or -apostrophe characters from string `doesn't this mean it -technically- works?`
re.sub("[^\\w' ]", '', "doesn't this mean it -technically- works?")
[ "python.library.re#re.sub" ]
re.sub("[^\\w' ]", '', 'VAR_STR')
conala
11530799-66
find the index of the element with the maximum value from a list 'a'.
max(enumerate(a), key=lambda x: x[1])[0]
[ "python.library.functions#enumerate", "python.library.functions#max" ]
max(enumerate(VAR_STR), key=lambda x: x[1])[0]
conala
29454773-91
Check if string 'a b' only contains letters and spaces
"""a b""".replace(' ', '').isalpha()
[ "python.library.stdtypes#str.isalpha", "python.library.stdtypes#str.replace" ]
"""VAR_STR""".replace(' ', '').isalpha()
conala
4008546-45
pad 'dog' up to a length of 5 characters with 'x'
"""{s:{c}^{n}}""".format(s='dog', n=5, c='x')
[ "python.library.functions#format" ]
"""{s:{c}^{n}}""".format(s='VAR_STR', n=5, c='VAR_STR')
conala
32926587-42
find all substrings in string `mystring` composed only of letters `a` and `b` where each `a` is directly preceded and succeeded by `b`
re.findall('\\b(?:b+a)+b+\\b', mystring)
[ "python.library.re#re.findall" ]
re.findall('\\b(?:b+a)+b+\\b', VAR_STR)
conala
14442636-72
check if a checkbox is checked in selenium python webdriver
driver.find_element_by_name('<check_box_name>').is_selected()
[]
driver.find_element_by_name('<check_box_name>').is_selected()
conala
14442636-50
determine if checkbox with id '<check_box_id>' is checked in selenium python webdriver
driver.find_element_by_id('<check_box_id>').is_selected()
[]
driver.find_element_by_id('VAR_STR').is_selected()
conala
7657457-75
Find all keys from a dictionary `d` whose values are `desired_value`
[k for k, v in d.items() if v == desired_value]
[ "python.library.stdtypes#dict.items" ]
[k for k, v in VAR_STR.items() if v == VAR_STR]
conala
20183069-6
sort a multidimensional array `a` by column with index 1
sorted(a, key=lambda x: x[1])
[ "python.library.functions#sorted" ]
sorted(VAR_STR, key=lambda x: x[1])
conala
3780403-38
sum the length of all strings in a list `strings`
length = sum(len(s) for s in strings)
[ "python.library.functions#len", "python.library.functions#sum" ]
length = sum(len(s) for s in VAR_STR)
conala
14986218-40
Convert a list of lists `lol` to a dictionary with key as second value of a list and value as list itself
{x[1]: x for x in lol}
[]
{x[1]: x for x in VAR_STR}
conala
14734533-87
get data of column 'A' and column 'B' in dataframe `df` where column 'A' is equal to 'foo'
df.loc[gb.groups['foo'], ('A', 'B')]
[ "pandas.reference.api.pandas.dataframe.loc" ]
VAR_STR.loc[gb.groups['VAR_STR'], ('VAR_STR', 'VAR_STR')]
conala
21684346-78
display a pdf file that has been downloaded as `my_pdf.pdf`
webbrowser.open('file:///my_pdf.pdf')
[ "python.library.webbrowser#webbrowser.open" ]
webbrowser.open('file:///my_pdf.pdf')
conala
2173797-93
sort 2d array `matrix` by row with index 1
sorted(matrix, key=itemgetter(1))
[ "python.library.functions#sorted", "python.library.operator#operator.itemgetter" ]
sorted(VAR_STR, key=itemgetter(1))
conala
39373620-92
get the max string length in list `i`
max(len(word) for word in i)
[ "python.library.functions#len", "python.library.functions#max" ]
max(len(word) for word in VAR_STR)
conala
39373620-74
get the maximum string length in nested list `i`
len(max(i, key=len))
[ "python.library.functions#len", "python.library.functions#max" ]
len(max(VAR_STR, key=len))
conala
17352321-10
find all occurrences of the pattern '\\[[^\\]]*\\]|\\([^\\)]*\\)|"[^"]*"|\\S+' within `strs`
re.findall('\\[[^\\]]*\\]|\\([^\\)]*\\)|"[^"]*"|\\S+', strs)
[ "python.library.re#re.findall" ]
re.findall('VAR_STR', VAR_STR)
conala
12572362-45
print a string after a specific substring ', ' in string `my_string `
print(my_string.split(', ', 1)[1])
[ "python.library.stdtypes#str.split" ]
print(VAR_STR.split(', ', 1)[1])
conala
677656-11
extract attribute `my_attr` from each object in list `my_list`
[o.my_attr for o in my_list]
[]
[o.VAR_STR for o in VAR_STR]
conala
13842088-36
set the value of cell `['x']['C']` equal to 10 in dataframe `df`
df['x']['C'] = 10
[]
VAR_STR[VAR_STR] = 10
conala
9621388-67
how to get month name of datetime `today`
today.strftime('%B')
[ "python.library.time#time.strftime" ]
VAR_STR.strftime('%B')
conala
9621388-54
get month name from a datetime object `today`
today.strftime('%B')
[ "python.library.time#time.strftime" ]
VAR_STR.strftime('%B')
conala
18050937-57
execute shell command 'grep -r PASSED *.log | sort -u | wc -l' with a | pipe in it
subprocess.call('grep -r PASSED *.log | sort -u | wc -l', shell=True)
[ "python.library.subprocess#subprocess.call" ]
subprocess.call('VAR_STR', shell=True)
conala
4004550-67
Converting string lists `s` to float list
floats = [float(x) for x in s.split()]
[ "python.library.functions#float", "python.library.stdtypes#str.split" ]
floats = [float(x) for x in VAR_STR.split()]
conala
4004550-27
Converting string lists `s` to float list
floats = map(float, s.split())
[ "python.library.functions#map", "python.library.stdtypes#str.split" ]
floats = map(float, VAR_STR.split())
conala
3476732-50
iterate backwards from 10 to 0
range(10, 0, -1)
[ "python.library.functions#range" ]
range(10, 0, -1)
conala
18742657-57
Execute Shell Script from python with variable
subprocess.call(['test.sh', str(domid)])
[ "python.library.subprocess#subprocess.call", "python.library.stdtypes#str" ]
subprocess.call(['test.sh', str(domid)])
conala
25355705-76
count the number of integers in list `a`
sum(isinstance(x, int) for x in a)
[ "python.library.functions#isinstance", "python.library.functions#sum" ]
sum(isinstance(x, int) for x in VAR_STR)
conala
307305-84
play the wav file 'sound.wav'
winsound.PlaySound('sound.wav', winsound.SND_FILENAME)
[ "python.library.winsound#winsound.PlaySound" ]
winsound.PlaySound('VAR_STR', winsound.SND_FILENAME)
conala
3040904-33
save json output from a url ‘http://search.twitter.com/search.json?q=hi’ to file ‘hi.json’ in Python 2
urllib.request.urlretrieve('http://search.twitter.com/search.json?q=hi', 'hi.json')
[ "python.library.urllib.request#urllib.request.urlretrieve" ]
urllib.request.urlretrieve('http://search.twitter.com/search.json?q=hi', 'hi.json')
conala
15886340-14
remove uppercased characters in string `s`
re.sub('[^A-Z]', '', s)
[ "python.library.re#re.sub" ]
re.sub('[^A-Z]', '', VAR_STR)
conala
37619348-38
Get a list of lists with summing the values of the second element from each list of lists `data`
[[sum([x[1] for x in i])] for i in data]
[ "python.library.functions#sum" ]
[[sum([x[1] for x in i])] for i in VAR_STR]
conala
37619348-52
summing the second item in a list of lists of lists
[sum([x[1] for x in i]) for i in data]
[ "python.library.functions#sum" ]
[sum([x[1] for x in i]) for i in data]
conala
22128218-47
apply functions `mean` and `std` to each column in dataframe `df`
df.groupby(lambda idx: 0).agg(['mean', 'std'])
[ "pandas.reference.api.pandas.dataframe.groupby", "pandas.reference.api.pandas.dataframe.agg" ]
VAR_STR.groupby(lambda idx: 0).agg(['VAR_STR', 'VAR_STR'])
conala
2269827-12
convert an int 65 to hex string
hex(65)
[ "python.library.functions#hex" ]
hex(65)
conala
21778118-32
count the number of non-nan elements in a numpy ndarray matrix `data`
np.count_nonzero(~np.isnan(data))
[ "numpy.reference.generated.numpy.count_nonzero", "numpy.reference.generated.numpy.isnan" ]
np.count_nonzero(~np.isnan(VAR_STR))
conala
2261011-58
How can I resize the root window in Tkinter?
root.geometry('500x500')
[]
root.geometry('500x500')
conala
19410585-47
add header 'WWWAuthenticate' in a flask app with value 'Basic realm="test"'
response.headers['WWW-Authenticate'] = 'Basic realm="test"'
[]
response.headers['WWW-Authenticate'] = 'VAR_STR'
conala
38331568-38
return the column for value 38.15 in dataframe `df`
df.ix[:, (df.loc[0] == 38.15)].columns
[ "pandas.reference.api.pandas.dataframe.loc" ]
VAR_STR.ix[:, (VAR_STR.loc[0] == 38.15)].columns
conala
13668393-94
sort two lists `list1` and `list2` together using lambda function
[list(x) for x in zip(*sorted(zip(list1, list2), key=lambda pair: pair[0]))]
[ "python.library.functions#zip", "python.library.functions#sorted", "python.library.functions#list" ]
[list(x) for x in zip(*sorted(zip(VAR_STR, VAR_STR), key=lambda pair: pair[0]))]
conala
22918212-12
drop duplicate indexes in a pandas data frame `df`
df[~df.index.duplicated()]
[ "pandas.reference.api.pandas.index.duplicated" ]
VAR_STR[~VAR_STR.index.duplicated()]
conala
9354127-56
grab one random item from a database `model` in django/postgresql
model.objects.all().order_by('?')[0]
[ "python.library.functions#all" ]
VAR_STR.objects.all().order_by('?')[0]
conala
2582580-92
select a first form with no name in mechanize
br.select_form(nr=0)
[]
br.select_form(nr=0)
conala
753052-14
strip html from strings
re.sub('<[^<]+?>', '', text)
[ "python.library.re#re.sub" ]
re.sub('<[^<]+?>', '', text)
conala
26033239-78
convert a list of objects `list_name` to json string `json_string`
json_string = json.dumps([ob.__dict__ for ob in list_name])
[ "python.library.json#json.dumps" ]
VAR_STR = json.dumps([ob.__dict__ for ob in VAR_STR])
conala
13168252-36
Get a list comparing two lists of tuples `l1` and `l2` if any first value in `l1` matches with first value in `l2`
[x[0] for x in l1 if any(x[0] == y[0] for y in l2)]
[ "python.library.functions#any" ]
[x[0] for x in VAR_STR if any(x[0] == y[0] for y in VAR_STR)]
conala
27758657-77
find the largest integer less than `x`
int(math.ceil(x)) - 1
[ "python.library.math#math.ceil", "python.library.functions#int" ]
int(math.ceil(VAR_STR)) - 1
conala
18082130-81
remove all words which contains number from a string `words` using regex
re.sub('\\w*\\d\\w*', '', words).strip()
[ "python.library.re#re.sub", "python.library.stdtypes#str.strip" ]
re.sub('\\w*\\d\\w*', '', VAR_STR).strip()
conala
18663644-86
match a sharp, followed by letters (including accent characters) in string `str1` using a regex
hashtags = re.findall('#(\\w+)', str1, re.UNICODE)
[ "python.library.re#re.findall" ]
hashtags = re.findall('#(\\w+)', VAR_STR, re.UNICODE)
conala
2133571-79
Concat a list of strings `lst` using string formatting
"""""".join(lst)
[ "python.library.stdtypes#str.join" ]
"""""".join(VAR_STR)
conala
7164679-63
send cookies `cookie` in a post request to url 'http://wikipedia.org' with the python requests library
r = requests.post('http://wikipedia.org', cookies=cookie)
[ "pygame.ref.fastevent#pygame.fastevent.post" ]
r = requests.post('VAR_STR', cookies=VAR_STR)
conala
15248272-21
list comprehension that produces integers between 11 and 19
[i for i in range(100) if i > 10 if i < 20]
[ "python.library.functions#range" ]
[i for i in range(100) if i > 10 if i < 20]
conala
300445-24
unquote a urlencoded unicode string '%0a'
urllib.parse.unquote('%0a')
[ "python.library.urllib.parse#urllib.parse.unquote" ]
urllib.parse.unquote('VAR_STR')
conala
300445-76
decode url `url` from UTF-16 code to UTF-8 code
urllib.parse.unquote(url).decode('utf8')
[ "python.library.urllib.parse#urllib.parse.unquote", "python.library.stdtypes#bytearray.decode" ]
urllib.parse.unquote(VAR_STR).decode('utf8')
conala
3961581-71
display current time in readable format
time.strftime('%l:%M%p %z on %b %d, %Y')
[ "python.library.time#time.strftime" ]
time.strftime('%l:%M%p %z on %b %d, %Y')
conala
27905295-6
replace nans by preceding values in pandas dataframe `df`
df.fillna(method='ffill', inplace=True)
[ "pandas.reference.api.pandas.dataframe.fillna" ]
VAR_STR.fillna(method='ffill', inplace=True)
conala
19643099-48
sort list `list_` based on first element of each tuple and by the length of the second element of each tuple
list_.sort(key=lambda x: [x[0], len(x[1]), x[1]])
[ "python.library.functions#len", "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=lambda x: [x[0], len(x[1]), x[1]])
conala
1683775-89
sort a multidimensional list `a` by second and third column
a.sort(key=operator.itemgetter(2, 3))
[ "python.library.operator#operator.itemgetter", "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=operator.itemgetter(2, 3))
conala
7270321-45
Get all indexes of a list `a` where each value is greater than `2`
[i for i in range(len(a)) if a[i] > 2]
[ "python.library.functions#len", "python.library.functions#range" ]
[i for i in range(len(VAR_STR)) if VAR_STR[i] > 2]
conala
5399112-45
replace special characters in url 'http://spam.com/go/' using the '%xx' escape
urllib.parse.quote('http://spam.com/go/')
[ "python.library.urllib.parse#urllib.parse.quote" ]
urllib.parse.quote('VAR_STR')
conala
5486725-74
execute a command in the command prompt to list directory contents of the c drive `c:\\'
os.system('dir c:\\')
[ "python.library.os#os.system" ]
os.system('dir c:\\')
conala
17846545-92
Compose keys from dictionary `d1` with respective values in dictionary `d2`
result = {k: d2.get(v) for k, v in list(d1.items())}
[ "python.library.functions#list", "django.ref.class-based-views.generic-display#django.views.generic.list.BaseListView.get", "python.library.stdtypes#dict.items" ]
result = {k: VAR_STR.get(v) for k, v in list(VAR_STR.items())}
conala
2191699-35
find all the elements that consists value '1' in a list of tuples 'a'
[item for item in a if 1 in item]
[]
[item for item in VAR_STR if 1 in item]
conala
2191699-81
find all elements in a list of tuples `a` where the first element of each tuple equals 1
[item for item in a if item[0] == 1]
[]
[item for item in VAR_STR if item[0] == 1]
conala
5625524-90
execute os command ''TASKKILL /F /IM firefox.exe''
os.system('TASKKILL /F /IM firefox.exe')
[ "python.library.os#os.system" ]
os.system('VAR_STR')
conala
123198-58
copy a file from `src` to `dst`
copyfile(src, dst)
[ "python.library.shutil#shutil.copyfile" ]
copyfile(VAR_STR, VAR_STR)
conala
123198-2
copy file "/dir/file.ext" to "/new/dir/newname.ext"
shutil.copy2('/dir/file.ext', '/new/dir/newname.ext')
[ "python.library.shutil#shutil.copy2" ]
shutil.copy2('VAR_STR', 'VAR_STR')
conala
123198-90
copy file '/dir/file.ext' to '/new/dir'
shutil.copy2('/dir/file.ext', '/new/dir')
[ "python.library.shutil#shutil.copy2" ]
shutil.copy2('VAR_STR', 'VAR_STR')
conala
17462994-4
Get a string with string formatting from dictionary `d`
""", """.join(['{}_{}'.format(k, v) for k, v in d.items()])
[ "python.library.functions#format", "python.library.stdtypes#dict.items", "python.library.stdtypes#str.join" ]
""", """.join(['{}_{}'.format(k, v) for k, v in VAR_STR.items()])
conala
227459-13
get the ASCII value of a character 'a' as an int
ord('a')
[ "python.library.functions#ord" ]
ord('VAR_STR')
conala
227459-75
get the ASCII value of a character u'あ' as an int
ord('\u3042')
[ "python.library.functions#ord" ]
ord('あ')
conala
227459-40
get the ASCII value of a character as an int
ord()
[ "python.library.functions#ord" ]
ord()
conala
1580270-33
What's the best way to search for a Python dictionary value in a list of dictionaries?
any(d['site'] == 'Superuser' for d in data)
[ "python.library.functions#any" ]
any(d['site'] == 'Superuser' for d in data)
conala
11414596-44
return dataframe `df` with last row dropped
df.ix[:-1]
[]
VAR_STR.ix[:-1]
conala
15103484-71
separate numbers from characters in string "30m1000n20m"
re.findall('(([0-9]+)([A-Z]))', '20M10000N80M')
[ "python.library.re#re.findall" ]
re.findall('(([0-9]+)([A-Z]))', '20M10000N80M')
conala
15103484-54
separate numbers and characters in string '20M10000N80M'
re.findall('([0-9]+|[A-Z])', '20M10000N80M')
[ "python.library.re#re.findall" ]
re.findall('([0-9]+|[A-Z])', 'VAR_STR')
conala