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
4879641-52
create a list containing all values associated with key 'baz' in dictionaries of list `foos` using list comprehension
[y['baz'] for x in foos for y in x['bar']]
[]
[y['VAR_STR'] for x in VAR_STR for y in x['bar']]
conala
5218948-78
Make a auto scrolled window to the end of the list in gtk
self.treeview.connect('size-allocate', self.treeview_changed)
[ "python.library.sqlite3#sqlite3.connect" ]
self.treeview.connect('size-allocate', self.treeview_changed)
conala
32490629-62
Getting today's date in YYYY-MM-DD
datetime.datetime.today().strftime('%Y-%m-%d')
[ "python.library.datetime#datetime.datetime.today", "python.library.datetime#datetime.datetime.strftime" ]
datetime.datetime.today().strftime('%Y-%m-%d')
conala
35883459-33
creating a list of dictionaries [{'A': 1, 'C': 4, 'B': 2, 'D': 4}, {'A': 1, 'C': 4, 'B': 1, 'D': 5}]
[{'A': 1, 'C': 4, 'B': 2, 'D': 4}, {'A': 1, 'C': 4, 'B': 1, 'D': 5}]
[]
[{'VAR_STR': 1, 'VAR_STR': 4, 'VAR_STR': 2, 'VAR_STR': 4}, {'VAR_STR': 1, 'VAR_STR': 4, 'VAR_STR': 1, 'VAR_STR': 5}]
conala
35883459-5
Creating a list of dictionaries in python
[{'A': 1, 'C': 4, 'B': 2, 'D': 4}, {'A': 1, 'C': 4, 'B': 1, 'D': 5}]
[]
[{'A': 1, 'C': 4, 'B': 2, 'D': 4}, {'A': 1, 'C': 4, 'B': 1, 'D': 5}]
conala
28669459-58
print variable `value ` without spaces
print('Value is "' + str(value) + '"')
[ "python.library.stdtypes#str" ]
print('Value is "' + str(VAR_STR) + '"')
conala
28669459-58
Print a string `value` with string formatting
print('Value is "{}"'.format(value))
[ "python.library.stdtypes#str" ]
print('Value is "{}"'.format(VAR_STR))
conala
13070461-75
get index of the biggest 2 values of a list `a`
sorted(list(range(len(a))), key=lambda i: a[i])[-2:]
[ "python.library.functions#sorted", "python.library.functions#len", "python.library.functions#range", "python.library.functions#list" ]
sorted(list(range(len(VAR_STR))), key=lambda i: VAR_STR[i])[-2:]
conala
13070461-22
get indexes of the largest `2` values from a list `a` using itemgetter
zip(*sorted(enumerate(a), key=operator.itemgetter(1)))[0][-2:]
[ "python.library.operator#operator.itemgetter", "python.library.functions#zip", "python.library.functions#sorted", "python.library.functions#enumerate" ]
zip(*sorted(enumerate(VAR_STR), key=operator.itemgetter(1)))[0][-2:]
conala
13070461-4
get the indexes of the largest `2` values from a list of integers `a`
sorted(list(range(len(a))), key=lambda i: a[i], reverse=True)[:2]
[ "python.library.functions#sorted", "python.library.functions#len", "python.library.functions#range", "python.library.functions#list" ]
sorted(list(range(len(VAR_STR))), key=lambda i: VAR_STR[i], reverse=True)[:2]
conala
13042013-50
adding url `url` to mysql row
cursor.execute('INSERT INTO index(url) VALUES(%s)', (url,))
[ "python.library.sqlite3#sqlite3.Cursor.execute" ]
cursor.execute('INSERT INTO index(url) VALUES(%s)', (VAR_STR,))
conala
7026131-18
fill list `myList` with 4 0's
self.myList.extend([0] * (4 - len(self.myList)))
[ "python.library.functions#len", "python.library.collections#collections.deque.extend" ]
self.VAR_STR.extend([0] * (4 - len(self.VAR_STR)))
conala
5917537-9
immediately see output of print statement that doesn't end in a newline
sys.stdout.flush()
[ "python.library.logging#logging.Handler.flush" ]
sys.stdout.flush()
conala
35253971-84
check if all values of a dictionary `your_dict` are zero `0`
all(value == 0 for value in list(your_dict.values()))
[ "python.library.functions#all", "python.library.functions#list", "python.library.stdtypes#dict.values" ]
all(value == 0 for value in list(VAR_STR.values()))
conala
8899905-32
count number of occurrences of a substring 'ab' in a string "abcdabcva"
"""abcdabcva""".count('ab')
[ "python.library.stdtypes#str.count" ]
"""VAR_STR""".count('VAR_STR')
conala
2151517-74
get the union set from list of lists `results_list`
results_union = set().union(*results_list)
[ "python.library.stdtypes#set", "python.library.stdtypes#frozenset.union" ]
results_union = set().union(*VAR_STR)
conala
2151517-30
get the union of values in list of lists `result_list`
return list(set(itertools.chain(*result_list)))
[ "python.library.itertools#itertools.chain", "python.library.functions#list", "python.library.stdtypes#set" ]
return list(set(itertools.chain(*VAR_STR)))
conala
952914-55
make a flat list from list of lists `sublist`
[item for sublist in l for item in sublist]
[]
[item for VAR_STR in l for item in VAR_STR]
conala
952914-41
make a flat list from list of lists `list2d`
list(itertools.chain(*list2d))
[ "python.library.itertools#itertools.chain", "python.library.functions#list" ]
list(itertools.chain(*VAR_STR))
conala
952914-3
make a flat list from list of lists `list2d`
list(itertools.chain.from_iterable(list2d))
[ "python.library.itertools#itertools.chain.from_iterable", "python.library.functions#list" ]
list(itertools.chain.from_iterable(VAR_STR))
conala
40221516-69
join two dataframes based on values in selected columns
pd.merge(a, b, on=['A', 'B'], how='outer')
[ "pandas.reference.api.pandas.merge" ]
pd.merge(a, b, on=['A', 'B'], how='outer')
conala
17193850-16
get all the values in column `b` from pandas data frame `df`
df['b']
[]
VAR_STR['VAR_STR']
conala
11619169-67
convert Date object `dateobject` into a DateTime object
datetime.datetime.combine(dateobject, datetime.time())
[ "python.library.datetime#datetime.datetime.combine", "python.library.datetime#datetime.time" ]
datetime.datetime.combine(VAR_STR, datetime.time())
conala
4108561-37
How to exclude a character from a regex group?
re.compile('[^a-zA-Z0-9-]+')
[ "python.library.re#re.compile" ]
re.compile('[^a-zA-Z0-9-]+')
conala
11620914-85
remove Nan values from array `x`
x = x[numpy.logical_not(numpy.isnan(x))]
[ "numpy.reference.generated.numpy.logical_not", "numpy.reference.generated.numpy.isnan" ]
VAR_STR = VAR_STR[numpy.logical_not(numpy.isnan(VAR_STR))]
conala
1012185-44
index a list `L` with another list `Idx`
T = [L[i] for i in Idx]
[]
T = [VAR_STR[i] for i in VAR_STR]
conala
17812978-84
How to plot two columns of a pandas data frame using points?
df.plot(x='col_name_1', y='col_name_2', style='o')
[ "pandas.reference.api.pandas.dataframe.plot" ]
df.plot(x='col_name_1', y='col_name_2', style='o')
conala
1249388-47
remove all non-numeric characters from string `sdkjh987978asd098as0980a98sd `
re.sub('[^0-9]', '', 'sdkjh987978asd098as0980a98sd')
[ "python.library.re#re.sub" ]
re.sub('[^0-9]', '', 'VAR_STR')
conala
176918-30
finding the index of an item 'foo' given a list `['foo', 'bar', 'baz']` containing it
[i for i, j in enumerate(['foo', 'bar', 'baz']) if j == 'foo']
[ "python.library.functions#enumerate" ]
[i for i, j in enumerate(['VAR_STR', 'bar', 'baz']) if j == 'VAR_STR']
conala
11264005-71
Validate IP address using Regex
pat = re.compile('^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$')
[ "python.library.re#re.compile" ]
pat = re.compile('^\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}$')
conala
8194156-97
subtract elements of list `List1` from elements of list `List2`
[(x1 - x2) for x1, x2 in zip(List1, List2)]
[ "python.library.functions#zip" ]
[(x1 - x2) for x1, x2 in zip(VAR_STR, VAR_STR)]
conala
3276180-66
extract date from a string 'monkey 2010-07-32 love banana'
dparser.parse('monkey 2010-07-32 love banana', fuzzy=True)
[ "python.library.ast#ast.parse" ]
dparser.parse('VAR_STR', fuzzy=True)
conala
3276180-20
extract date from a string 'monkey 20/01/1980 love banana'
dparser.parse('monkey 20/01/1980 love banana', fuzzy=True)
[ "python.library.ast#ast.parse" ]
dparser.parse('VAR_STR', fuzzy=True)
conala
3276180-87
extract date from a string `monkey 10/01/1980 love banana`
dparser.parse('monkey 10/01/1980 love banana', fuzzy=True)
[ "python.library.ast#ast.parse" ]
dparser.parse('VAR_STR', fuzzy=True)
conala
11277432-32
remove a key 'key' from a dictionary `my_dict`
my_dict.pop('key', None)
[ "python.library.stdtypes#dict.pop" ]
VAR_STR.pop('VAR_STR', None)
conala
521502-6
How to get the concrete class name as a string?
instance.__class__.__name__
[]
instance.__class__.__name__
conala
17474211-72
sort list `a` in ascending order based on its elements' float values
a = sorted(a, key=lambda x: float(x))
[ "python.library.functions#sorted", "python.library.functions#float" ]
VAR_STR = sorted(VAR_STR, key=lambda x: float(x))
conala
11850425-35
Sort list `alist` in ascending order based on each of its elements' attribute `foo`
alist.sort(key=lambda x: x.foo)
[ "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=lambda x: x.VAR_STR)
conala
13223737-73
open file '5_1.txt' in directory `direct`
x_file = open(os.path.join(direct, '5_1.txt'), 'r')
[ "python.library.os.path#os.path.join", "python.library.urllib.request#open" ]
x_file = open(os.path.join(VAR_STR, 'VAR_STR'), 'r')
conala
3685265-84
save numpy array `x` into text file 'test.txt'
np.savetxt('test.txt', x)
[ "numpy.reference.generated.numpy.savetxt" ]
np.savetxt('VAR_STR', VAR_STR)
conala
29760130-12
get the list with the highest sum value in list `x`
print(max(x, key=sum))
[ "python.library.functions#max" ]
print(max(VAR_STR, key=sum))
conala
4800811-3
get the value at index 1 for each tuple in the list of tuples `L`
[x[1] for x in L]
[]
[x[1] for x in VAR_STR]
conala
2508861-5
Python: Convert a string to an integer
int(' 23 ')
[ "python.library.functions#int" ]
int(' 23 ')
conala
11348347-44
create a set that is the exclusive or of [1, 2, 3] and [3, 4, 5]
set([1, 2, 3]) ^ set([3, 4, 5])
[ "python.library.stdtypes#set" ]
set([1, 2, 3]) ^ set([3, 4, 5])
conala
7732125-28
if Selenium textarea element `foo` is not empty, clear the field
driver.find_element_by_id('foo').clear()
[ "python.library.stdtypes#frozenset.clear" ]
driver.find_element_by_id('VAR_STR').clear()
conala
7732125-17
clear text from textarea 'foo' with selenium
driver.find_element_by_id('foo').clear()
[ "python.library.stdtypes#frozenset.clear" ]
driver.find_element_by_id('VAR_STR').clear()
conala
7974442-3
make a function `f` that calculates the sum of two integer variables `x` and `y`
f = lambda x, y: x + y
[]
VAR_STR = lambda VAR_STR, VAR_STR: VAR_STR + VAR_STR
conala
3365673-3
throw an error window in python in windows
ctypes.windll.user32.MessageBoxW(0, 'Error', 'Error', 0)
[]
ctypes.windll.user32.MessageBoxW(0, 'Error', 'Error', 0)
conala
19585280-52
convert rows in pandas data frame `df` into list
df.apply(lambda x: x.tolist(), axis=1)
[ "pandas.reference.api.pandas.dataframe.apply", "pandas.reference.api.pandas.series.tolist" ]
VAR_STR.apply(lambda x: x.tolist(), axis=1)
conala
2742784-42
round 123 to 100
int(round(123, -2))
[ "python.library.functions#int", "python.library.functions#round" ]
int(round(123, -2))
conala
367155-83
split a unicode string `text` into a list of words and punctuation characters with a regex
re.findall('\\w+|[^\\w\\s]', text, re.UNICODE)
[ "python.library.re#re.findall" ]
re.findall('\\w+|[^\\w\\s]', VAR_STR, re.UNICODE)
conala
32511444-44
sum all the values in a counter variable `my_counter`
sum(my_counter.values())
[ "python.library.functions#sum", "python.library.stdtypes#dict.values" ]
sum(VAR_STR.values())
conala
7253907-19
convert 3652458 to string represent a 32bit hex number
"""0x{0:08X}""".format(3652458)
[ "python.library.functions#format" ]
"""0x{0:08X}""".format(3652458)
conala
17895835-63
print two numbers `10` and `20` using string formatting
"""{0} {1}""".format(10, 20)
[ "python.library.functions#format" ]
"""{0} {1}""".format(10, 20)
conala
17895835-19
replace placeholders in string '{1} {ham} {0} {foo} {1}' with arguments `(10, 20, foo='bar', ham='spam')`
"""{1} {ham} {0} {foo} {1}""".format(10, 20, foo='bar', ham='spam')
[ "python.library.functions#format" ]
"""VAR_STR""".format(VAR_STR)
conala
14431731-59
insert string `string1` after each character of `string2`
string2.replace('', string1)[len(string1):-len(string1)]
[ "python.library.functions#len", "python.library.stdtypes#str.replace" ]
VAR_STR.replace('', VAR_STR)[len(VAR_STR):-len(VAR_STR)]
conala
3899782-68
check whether elements in list `a` appear only once
len(set(a)) == len(a)
[ "python.library.functions#len", "python.library.stdtypes#set" ]
len(set(VAR_STR)) == len(VAR_STR)
conala
15839491-63
clear Tkinter Canvas `canvas`
canvas.delete('all')
[ "python.library.ast#ast.Delete" ]
VAR_STR.delete('all')
conala
4524723-100
take screenshot 'screen.png' on mac os x
os.system('screencapture screen.png')
[ "python.library.os#os.system" ]
os.system('screencapture screen.png')
conala
11621165-35
Reset the indexes of a pandas data frame
df2 = df.reset_index()
[ "pandas.reference.api.pandas.dataframe.reset_index" ]
df2 = df.reset_index()
conala
17618981-15
sort pandas data frame `df` using values from columns `c1` and `c2` in ascending order
df.sort(['c1', 'c2'], ascending=[True, True])
[ "pandas.reference.api.pandas.index.sort" ]
VAR_STR.sort(['VAR_STR', 'VAR_STR'], ascending=[True, True])
conala
8372399-59
Get the zip output as list from the lists `[1, 2, 3]`, `[4, 5, 6]`, `[7, 8, 9]`
[list(a) for a in zip([1, 2, 3], [4, 5, 6], [7, 8, 9])]
[ "python.library.functions#zip", "python.library.functions#list" ]
[list(a) for a in zip([VAR_STR], [VAR_STR], [VAR_STR])]
conala
14306852-84
modify the width of a text control as `300` keeping default height in wxpython
wx.TextCtrl(self, -1, size=(300, -1))
[]
wx.TextCtrl(self, -1, size=(300, -1))
conala
2769061-34
erase the contents of a file `filename`
open('filename', 'w').close()
[ "python.library.urllib.request#open" ]
open('VAR_STR', 'w').close()
conala
2769061-2
How to erase the file contents of text file in Python?
open('file.txt', 'w').close()
[ "python.library.urllib.request#open" ]
open('file.txt', 'w').close()
conala
15650538-28
Create sub matrix of a list of lists `[[2, 3, 4], [2, 3, 4], [2, 3, 4]]` (without numpy)
[[2, 3, 4], [2, 3, 4], [2, 3, 4]]
[]
[VAR_STR]
conala
25817930-59
sort each row in a pandas dataframe `df` in descending order
df.sort(axis=1, ascending=False)
[ "pandas.reference.api.pandas.index.sort" ]
VAR_STR.sort(axis=1, ascending=False)
conala
25817930-65
Fastest way to sort each row in a pandas dataframe
df.sort(df.columns, axis=1, ascending=False)
[]
df.sort(df.columns, axis=1, ascending=False)
conala
18397805-56
delete all rows in a numpy array `a` where any value in a row is zero `0`
a[np.all(a != 0, axis=1)]
[ "numpy.reference.generated.numpy.all" ]
VAR_STR[np.all(VAR_STR != 0, axis=1)]
conala
19156472-33
sort array `order_array` based on column 'year', 'month' and 'day'
order_array.sort(order=['year', 'month', 'day'])
[ "python.library.stdtypes#list.sort" ]
VAR_STR.sort(order=['VAR_STR', 'VAR_STR', 'VAR_STR'])
conala
19156472-7
Sort a structured numpy array 'df' on multiple columns 'year', 'month' and 'day'.
df.sort(['year', 'month', 'day'])
[ "pandas.reference.api.pandas.index.sort" ]
VAR_STR.sort(['VAR_STR', 'VAR_STR', 'VAR_STR'])
conala
11303225-39
remove multiple values from a list `my_list` at the same time with index starting at `2` and ending just before `6`.
del my_list[2:6]
[]
del VAR_STR[2:6]
conala
18366797-79
pandas read comma-separated CSV file `s` and skip commented lines starting with '#'
pd.read_csv(StringIO(s), sep=',', comment='#')
[ "pandas.reference.api.pandas.read_csv", "python.library.io#io.StringIO" ]
pd.read_csv(StringIO(VAR_STR), sep=',', comment='VAR_STR')
conala
251464-30
get a name of function `my_function` as a string
my_function.__name__
[]
VAR_STR.__name__
conala
251464-61
How to get a function name as a string in Python?
my_function.__name__
[]
my_function.__name__
conala
962619-48
get a random record from model 'MyModel' using django's orm
MyModel.objects.order_by('?').first()
[ "pandas.reference.api.pandas.dataframe.first" ]
VAR_STR.objects.order_by('?').first()
conala
3506678-35
in Django, select 100 random records from the database `Content.objects`
Content.objects.all().order_by('?')[:100]
[ "python.library.functions#all" ]
Content.objects.all().order_by('?')[:100]
conala
38549915-39
Merge all columns in dataframe `df` into one column
df.apply(' '.join, axis=0)
[ "pandas.reference.api.pandas.dataframe.apply" ]
VAR_STR.apply(' '.join, axis=0)
conala
8687568-13
write a tuple of tuples `A` to a csv file using python
writer.writerow(A)
[ "python.library.csv#csv.csvwriter.writerow" ]
writer.writerow(VAR_STR)
conala
8687568-40
Write all tuple of tuples `A` at once into csv file
writer.writerows(A)
[ "python.library.csv#csv.csvwriter.writerows" ]
writer.writerows(VAR_STR)
conala
9905471-69
split string `s` to list conversion by ','
[x.strip() for x in s.split(',')]
[ "python.library.stdtypes#str.strip", "python.library.stdtypes#str.split" ]
[x.strip() for x in VAR_STR.split('VAR_STR')]
conala
3895424-5
delete all elements from a list `x` if a function `fn` taking value as parameter returns `0`
[x for x in lst if fn(x) != 0]
[]
[VAR_STR for VAR_STR in lst if VAR_STR(VAR_STR) != 0]
conala
6856119-91
execute command 'source .bashrc; shopt -s expand_aliases; nuke -x scriptPath' from python script
os.system('source .bashrc; shopt -s expand_aliases; nuke -x scriptPath')
[ "python.library.os#os.system" ]
os.system('VAR_STR')
conala
2075128-48
Format all floating variables `var1`, `var2`, `var3`, `var1` to print to two decimal places.
print('%.2f kg = %.2f lb = %.2f gal = %.2f l' % (var1, var2, var3, var4))
[]
print('%.2f kg = %.2f lb = %.2f gal = %.2f l' % (VAR_STR, VAR_STR, VAR_STR, var4))
conala
18816297-75
Get the index value in list `p_list` using enumerate in list comprehension
{p.id: {'id': p.id, 'position': ind} for ind, p in enumerate(p_list)}
[ "python.library.functions#enumerate" ]
{p.id: {'id': p.id, 'position': ind} for ind, p in enumerate(VAR_STR)}
conala
15863066-99
Python regular expression match whole word
re.search('\\bis\\b', your_string)
[ "python.library.re#re.search" ]
re.search('\\bis\\b', your_string)
conala
19954469-63
Set the resolution of a monitor as `FULLSCREEN` in pygame
pygame.display.set_mode((0, 0), pygame.FULLSCREEN)
[ "pygame.ref.display#pygame.display.set_mode" ]
pygame.display.set_mode((0, 0), pygame.VAR_STR)
conala
20457174-80
find button that is in li class `next` and assign it to variable `next`
next = driver.find_element_by_css_selector('li.next>a')
[]
VAR_STR = driver.find_element_by_css_selector('li.next>a')
conala
6018340-91
match regex 'abc(de)fg(123)' on string 'abcdefg123 and again abcdefg123'
re.findall('abc(de)fg(123)', 'abcdefg123 and again abcdefg123')
[ "python.library.re#re.findall" ]
re.findall('VAR_STR', 'VAR_STR')
conala
14332141-67
Move the cursor of file pointer `fh1` at the end of the file.
fh1.seek(2)
[ "python.library.io#io.IOBase.seek" ]
VAR_STR.seek(2)
conala
14956683-99
Get the value of the minimum element in the second column of array `a`
a[np.argmin(a[:, (1)])]
[ "numpy.reference.generated.numpy.argmin" ]
VAR_STR[np.argmin(VAR_STR[:, (1)])]
conala
2655956-72
create a list containing elements of list `a` if the sum of the element is greater than 10
[item for item in a if sum(item) > 10]
[ "python.library.functions#sum" ]
[item for item in VAR_STR if sum(item) > 10]
conala
18637651-100
to convert a list of tuples `list_of_tuples` into list of lists
[list(t) for t in zip(*list_of_tuples)]
[ "python.library.functions#zip", "python.library.functions#list" ]
[list(t) for t in zip(*VAR_STR)]
conala
18637651-49
group a list `list_of_tuples` of tuples by values
zip(*list_of_tuples)
[ "python.library.functions#zip" ]
zip(*VAR_STR)
conala
9304408-69
Add 1 to each integer value in list `my_list`
new_list = [(x + 1) for x in my_list]
[]
new_list = [(x + 1) for x in VAR_STR]
conala
265960-7
Strip punctuation from string `s`
s.translate(None, string.punctuation)
[ "python.library.stdtypes#str.translate" ]
VAR_STR.translate(None, string.punctuation)
conala
35118265-63
remove the last dot and all text beyond it in string `s`
re.sub('\\.[^.]+$', '', s)
[ "python.library.re#re.sub" ]
re.sub('\\.[^.]+$', '', VAR_STR)
conala
2407398-46
merge lists `list_a` and `list_b` into a list of tuples
zip(list_a, list_b)
[ "python.library.functions#zip" ]
zip(VAR_STR, VAR_STR)
conala
2407398-69
merge lists `a` and `a` into a list of tuples
list(zip(a, b))
[ "python.library.functions#zip", "python.library.functions#list" ]
list(zip(VAR_STR, b))
conala
19035186-84
How to select element with Selenium Python xpath
driver.find_element_by_xpath("//div[@id='a']//a[@class='click']")
[]
driver.find_element_by_xpath("//div[@id='a']//a[@class='click']")
conala