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
19601086-21
click a href button having text `Send InMail` with selenium
driver.findElement(By.linkText('Send InMail')).click()
[]
driver.findElement(By.linkText('VAR_STR')).click()
conala
19601086-18
click a href button with text 'Send InMail' with selenium
driver.find_element_by_link_text('Send InMail').click()
[]
driver.find_element_by_link_text('VAR_STR').click()
conala
3944876-69
cast an int `i` to a string and concat to string 'ME'
'ME' + str(i)
[ "python.library.stdtypes#str" ]
'VAR_STR' + str(VAR_STR)
conala
40903174-8
Sorting data in DataFrame Pandas
df.sort_values(['System_num', 'Dis'])
[ "pandas.reference.api.pandas.dataframe.sort_values" ]
df.sort_values(['System_num', 'Dis'])
conala
19729928-41
sort a list `l` by length of value in tuple
l.sort(key=lambda t: len(t[1]), reverse=True)
[ "python.library.functions#len", "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=lambda t: len(t[1]), reverse=True)
conala
31371879-21
split string `s` by words that ends with 'd'
re.findall('\\b(\\w+)d\\b', s)
[ "python.library.re#re.findall" ]
re.findall('\\b(\\w+)d\\b', VAR_STR)
conala
4284648-18
convert elements of each tuple in list `l` into a string separated by character `@`
""" """.join([('%d@%d' % t) for t in l])
[ "python.library.stdtypes#str.join" ]
""" """.join([('%d@%d' % t) for t in VAR_STR])
conala
4284648-27
convert each tuple in list `l` to a string with '@' separating the tuples' elements
""" """.join([('%d@%d' % (t[0], t[1])) for t in l])
[ "python.library.stdtypes#str.join" ]
""" """.join([('%d@%d' % (t[0], t[1])) for t in VAR_STR])
conala
26809954-5
get the html from the current web page of a Selenium driver
driver.execute_script('return document.documentElement.outerHTML;')
[]
driver.execute_script('return document.documentElement.outerHTML;')
conala
29696641-55
Get all matches with regex pattern `\\d+[xX]` in list of string `teststr`
[i for i in teststr if re.search('\\d+[xX]', i)]
[ "python.library.re#re.search" ]
[i for i in VAR_STR if re.search('VAR_STR', i)]
conala
15315452-50
select values from column 'A' for which corresponding values in column 'B' will be greater than 50, and in column 'C' - equal 900 in dataframe `df`
df['A'][(df['B'] > 50) & (df['C'] == 900)]
[]
VAR_STR['VAR_STR'][(VAR_STR['VAR_STR'] > 50) & (VAR_STR['VAR_STR'] == 900)]
conala
4642501-94
Sort dictionary `o` in ascending order based on its keys and items
sorted(o.items())
[ "python.library.functions#sorted", "python.library.stdtypes#dict.items" ]
sorted(VAR_STR.items())
conala
4642501-41
get sorted list of keys of dict `d`
sorted(d)
[ "python.library.functions#sorted" ]
sorted(VAR_STR)
conala
4642501-26
How to sort dictionaries by keys in Python
sorted(d.items())
[ "python.library.functions#sorted", "python.library.stdtypes#dict.items" ]
sorted(d.items())
conala
642154-86
convert string "1" into integer
int('1')
[ "python.library.functions#int" ]
int('VAR_STR')
conala
642154-48
function to convert strings into integers
int()
[ "python.library.functions#int" ]
int()
conala
642154-35
convert items in `T1` to integers
T2 = [map(int, x) for x in T1]
[ "python.library.functions#map" ]
T2 = [map(int, x) for x in VAR_STR]
conala
3777301-68
call a shell script `./test.sh` using subprocess
subprocess.call(['./test.sh'])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['VAR_STR'])
conala
3777301-80
call a shell script `notepad` using subprocess
subprocess.call(['notepad'])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['VAR_STR'])
conala
7946798-38
combine lists `l1` and `l2` by alternating their elements
[val for pair in zip(l1, l2) for val in pair]
[ "python.library.functions#zip" ]
[val for pair in zip(VAR_STR, VAR_STR) for val in pair]
conala
7856296-87
parse tab-delimited CSV file 'text.txt' into a list
lol = list(csv.reader(open('text.txt', 'rb'), delimiter='\t'))
[ "python.library.csv#csv.reader", "python.library.functions#list", "python.library.urllib.request#open" ]
lol = list(csv.reader(open('VAR_STR', 'rb'), delimiter='\t'))
conala
5558418-19
group a list of dicts `LD` into one dict by key
print(dict(zip(LD[0], zip(*[list(d.values()) for d in LD]))))
[ "python.library.functions#zip", "python.library.stdtypes#dict", "python.library.functions#list", "python.library.stdtypes#dict.values" ]
print(dict(zip(VAR_STR[0], zip(*[list(d.values()) for d in VAR_STR]))))
conala
638048-68
How do I sum the first value in each tuple in a list of tuples in Python?
sum([pair[0] for pair in list_of_pairs])
[ "python.library.functions#sum" ]
sum([pair[0] for pair in list_of_pairs])
conala
14950260-11
convert unicode string u"{'code1':1,'code2':1}" into dictionary
d = ast.literal_eval("{'code1':1,'code2':1}")
[ "python.library.ast#ast.literal_eval" ]
d = ast.literal_eval('VAR_STR')
conala
11416772-97
find all words in a string `mystring` that start with the `$` sign
[word for word in mystring.split() if word.startswith('$')]
[ "python.library.stdtypes#str.startswith", "python.library.stdtypes#str.split" ]
[word for word in VAR_STR.split() if word.startswith('VAR_STR')]
conala
11331982-33
remove any url within string `text`
text = re.sub('^https?:\\/\\/.*[\\r\\n]*', '', text, flags=re.MULTILINE)
[ "python.library.re#re.sub" ]
VAR_STR = re.sub('^https?:\\/\\/.*[\\r\\n]*', '', VAR_STR, flags=re.MULTILINE)
conala
19894365-51
running r script '/pathto/MyrScript.r' from python
subprocess.call(['/usr/bin/Rscript', '--vanilla', '/pathto/MyrScript.r'])
[ "python.library.subprocess#subprocess.call" ]
subprocess.call(['/usr/bin/Rscript', '--vanilla', 'VAR_STR'])
conala
19894365-72
run r script '/usr/bin/Rscript --vanilla /pathto/MyrScript.r'
subprocess.call('/usr/bin/Rscript --vanilla /pathto/MyrScript.r', shell=True)
[ "python.library.subprocess#subprocess.call" ]
subprocess.call('VAR_STR', shell=True)
conala
33058590-67
replacing nan in the dataframe `df` with row average
df.fillna(df.mean(axis=1), axis=1)
[ "pandas.reference.api.pandas.dataframe.fillna", "pandas.reference.api.pandas.dataframe.mean" ]
VAR_STR.fillna(VAR_STR.mean(axis=1), axis=1)
conala
12400256-14
Convert unix timestamp '1347517370' to formatted string '%Y-%m-%d %H:%M:%S'
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(1347517370))
[ "python.library.time#time.localtime", "python.library.time#time.strftime" ]
time.strftime('VAR_STR', time.localtime(1347517370))
conala
1269217-89
Call a base class's class method `do` from derived class `Derived`
super(Derived, cls).do(a)
[ "python.library.functions#super" ]
super(VAR_STR, cls).VAR_STR(a)
conala
4383082-35
separate words delimited by one or more spaces into a list
re.split(' +', 'hello world sample text')
[ "python.library.re#re.split" ]
re.split(' +', 'hello world sample text')
conala
14637696-27
length of longest element in list `words`
len(max(words, key=len))
[ "python.library.functions#len", "python.library.functions#max" ]
len(max(VAR_STR, key=len))
conala
3933478-38
get the value associated with unicode key 'from_user' of first dictionary in list `result`
result[0]['from_user']
[]
VAR_STR[0]['VAR_STR']
conala
39112645-91
Retrieve each line from a file 'File.txt' as a list
[line.split() for line in open('File.txt')]
[ "python.library.urllib.request#open", "python.library.stdtypes#str.split" ]
[line.split() for line in open('VAR_STR')]
conala
1031851-75
swap keys with values in a dictionary `a`
res = dict((v, k) for k, v in a.items())
[ "python.library.stdtypes#dict", "python.library.stdtypes#dict.items" ]
res = dict((v, k) for k, v in VAR_STR.items())
conala
8577137-50
Open a file `path/to/FILE_NAME.ext` in write mode
new_file = open('path/to/FILE_NAME.ext', 'w')
[ "python.library.urllib.request#open" ]
new_file = open('VAR_STR', 'w')
conala
17926273-6
How to count distinct values in a column of a pandas group by object?
df.groupby(['col1', 'col2'])['col3'].nunique().reset_index()
[ "pandas.reference.api.pandas.dataframe.groupby", "pandas.reference.api.pandas.dataframe.reset_index", "pandas.reference.api.pandas.dataframe.nunique" ]
df.groupby(['col1', 'col2'])['col3'].nunique().reset_index()
conala
3735814-44
Check if any key in the dictionary `dict1` starts with the string `EMP$$`
any(key.startswith('EMP$$') for key in dict1)
[ "python.library.functions#any", "python.library.stdtypes#str.startswith" ]
any(key.startswith('VAR_STR') for key in VAR_STR)
conala
3735814-56
create list of values from dictionary `dict1` that have a key that starts with 'EMP$$'
[value for key, value in list(dict1.items()) if key.startswith('EMP$$')]
[ "python.library.functions#list", "python.library.stdtypes#str.startswith", "python.library.stdtypes#dict.items" ]
[value for key, value in list(VAR_STR.items()) if key.startswith('VAR_STR')]
conala
4048964-99
print elements of list `list` seperated by tabs `\t`
print('\t'.join(map(str, list)))
[ "python.library.functions#map", "python.library.stdtypes#str.join" ]
print('VAR_STR'.join(map(str, VAR_STR)))
conala
3182716-62
print unicode string '\xd0\xbf\xd1\x80\xd0\xb8' with utf-8
print('\xd0\xbf\xd1\x80\xd0\xb8'.encode('raw_unicode_escape'))
[ "python.library.stdtypes#str.encode" ]
print('VAR_STR'.encode('raw_unicode_escape'))
conala
3182716-21
Encode a latin character in string `Sopet\xc3\xb3n` properly
'Sopet\xc3\xb3n'.encode('latin-1').decode('utf-8')
[ "python.library.stdtypes#str.encode", "python.library.stdtypes#bytearray.decode" ]
"""VAR_STR""".encode('latin-1').decode('utf-8')
conala
35622945-39
regex, find "n"s only in the middle of string `s`
re.findall('n(?<=[^n]n)n+(?=[^n])(?i)', s)
[ "python.library.re#re.findall" ]
re.findall('n(?<=[^n]n)n+(?=[^n])(?i)', VAR_STR)
conala
5306756-0
display the float `1/3*100` as a percentage
print('{0:.0f}%'.format(1.0 / 3 * 100))
[ "python.library.functions#format" ]
print('{0:.0f}%'.format(1.0 / 3 * 100))
conala
2878084-9
sort a list of dictionary `mylist` by the key `title`
mylist.sort(key=lambda x: x['title'])
[ "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=lambda x: x['VAR_STR'])
conala
2878084-61
sort a list `l` of dicts by dict value 'title'
l.sort(key=lambda x: x['title'])
[ "python.library.stdtypes#list.sort" ]
VAR_STR.sort(key=lambda x: x['VAR_STR'])
conala
2878084-50
sort a list of dictionaries by the value of keys 'title', 'title_url', 'id' in ascending order.
l.sort(key=lambda x: (x['title'], x['title_url'], x['id']))
[ "python.library.stdtypes#list.sort" ]
l.sort(key=lambda x: (x['VAR_STR'], x['VAR_STR'], x['VAR_STR']))
conala
24189150-87
write records in dataframe `df` to table 'test' in schema 'a_schema'
df.to_sql('test', engine, schema='a_schema')
[ "pandas.reference.api.pandas.dataframe.to_sql" ]
VAR_STR.to_sql('VAR_STR', engine, schema='VAR_STR')
conala
30766151-61
Extract brackets from string `s`
brackets = re.sub('[^(){}[\\]]', '', s)
[ "python.library.re#re.sub" ]
brackets = re.sub('[^(){}[\\]]', '', VAR_STR)
conala
1143379-23
remove duplicate elements from list 'L'
list(dict((x[0], x) for x in L).values())
[ "python.library.stdtypes#dict", "python.library.functions#list", "python.library.stdtypes#dict.values" ]
list(dict((x[0], x) for x in VAR_STR).values())
conala
12330522-51
read a file `file` without newlines
[line.rstrip('\n') for line in file]
[ "python.library.stdtypes#str.rstrip" ]
[line.rstrip('\n') for line in VAR_STR]
conala
364621-80
get the position of item 1 in `testlist`
[i for (i, x) in enumerate(testlist) if (x == 1)]
[ "python.library.functions#enumerate" ]
[i for i, x in enumerate(VAR_STR) if x == 1]
conala
364621-61
get the position of item 1 in `testlist`
[i for (i, x) in enumerate(testlist) if (x == 1)]
[ "python.library.functions#enumerate" ]
[i for i, x in enumerate(VAR_STR) if x == 1]
conala
364621-20
get the position of item 1 in `testlist`
for i in [i for (i, x) in enumerate(testlist) if (x == 1)]: pass
[ "python.library.functions#enumerate" ]
for i in [i for i, x in enumerate(VAR_STR) if x == 1]: pass
conala
364621-36
get the position of item 1 in `testlist`
for i in (i for (i, x) in enumerate(testlist) if (x == 1)): pass
[ "python.library.functions#enumerate" ]
for i in (i for i, x in enumerate(VAR_STR) if x == 1): pass
conala
364621-75
get the position of item 1 in `testlist`
gen = (i for (i, x) in enumerate(testlist) if (x == 1)) for i in gen: pass
[ "python.library.functions#enumerate" ]
gen = (i for i, x in enumerate(VAR_STR) if x == 1) for i in gen: pass
conala
364621-47
get the position of item `element` in list `testlist`
print(testlist.index(element))
[ "python.library.stdtypes#str.index" ]
print(VAR_STR.index(VAR_STR))
conala
364621-83
get the position of item `element` in list `testlist`
try: print(testlist.index(element)) except ValueError: pass
[ "python.library.stdtypes#str.index" ]
try: print(VAR_STR.index(VAR_STR)) except ValueError: pass
conala
13145368-76
find the first element of the tuple with the maximum second element in a list of tuples `lis`
max(lis, key=lambda item: item[1])[0]
[ "python.library.functions#max" ]
max(VAR_STR, key=lambda item: item[1])[0]
conala
13145368-44
get the item at index 0 from the tuple that has maximum value at index 1 in list `lis`
max(lis, key=itemgetter(1))[0]
[ "python.library.functions#max", "python.library.operator#operator.itemgetter" ]
max(VAR_STR, key=itemgetter(1))[0]
conala
2689189-26
Make a delay of 1 second
time.sleep(1)
[ "python.library.time#time.sleep" ]
time.sleep(1)
conala
12485244-21
convert list of tuples `L` to a string
""", """.join('(' + ', '.join(i) + ')' for i in L)
[ "python.library.stdtypes#str.join" ]
""", """.join('(' + ', '.join(i) + ')' for i in VAR_STR)
conala
755857-66
Django set default value of field `b` equal to '0000000'
b = models.CharField(max_length=7, default='0000000', editable=False)
[ "django.ref.forms.fields#django.forms.CharField" ]
VAR_STR = models.CharField(max_length=7, default='VAR_STR', editable=False)
conala
16041405-85
convert a list into a generator object
(n for n in [1, 2, 3, 5])
[]
(n for n in [1, 2, 3, 5])
conala
18837607-60
remove elements from list `oldlist` that have an index number mentioned in list `removelist`
newlist = [v for i, v in enumerate(oldlist) if i not in removelist]
[ "python.library.functions#enumerate" ]
newlist = [v for i, v in enumerate(VAR_STR) if i not in VAR_STR]
conala
4710067-84
Open a file `yourfile.txt` in write mode
f = open('yourfile.txt', 'w')
[ "python.library.urllib.request#open" ]
f = open('VAR_STR', 'w')
conala
8171751-92
convert tuple of tuples `(('aa',), ('bb',), ('cc',))` to tuple
from functools import reduce reduce(lambda a, b: a + b, (('aa',), ('bb',), ('cc',)))
[]
from functools import reduce reduce(lambda a, b: a + b, (VAR_STR))
conala
8171751-59
convert tuple of tuples `(('aa',), ('bb',), ('cc',))` to list in one line
map(lambda a: a[0], (('aa',), ('bb',), ('cc',)))
[ "python.library.functions#map" ]
map(lambda a: a[0], (VAR_STR))
conala
28986489-84
Python Pandas: How to replace a characters in a column of a dataframe?
df['range'].replace(',', '-', inplace=True)
[ "python.library.stdtypes#str.replace" ]
df['range'].replace(',', '-', inplace=True)
conala
19339-13
unzip the list `[('a', 1), ('b', 2), ('c', 3), ('d', 4)]`
zip(*[('a', 1), ('b', 2), ('c', 3), ('d', 4)])
[ "python.library.functions#zip" ]
zip(*[VAR_STR])
conala
19339-3
unzip the list `[('a', 1), ('b', 2), ('c', 3), ('d', 4)]`
zip(*[('a', 1), ('b', 2), ('c', 3), ('d', 4)])
[ "python.library.functions#zip" ]
zip(*[VAR_STR])
conala
19339-46
unzip list `original`
result = ([a for (a, b) in original], [b for (a, b) in original])
[]
result = [a for a, b in VAR_STR], [b for a, b in VAR_STR]
conala
19339-60
unzip list `original` and return a generator
result = ((a for (a, b) in original), (b for (a, b) in original))
[]
result = (a for a, b in VAR_STR), (b for a, b in VAR_STR)
conala
19339-8
unzip list `[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', )]`
zip(*[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e',)])
[ "python.library.functions#zip" ]
zip(*[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e',)])
conala
19339-17
unzip list `[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', )]` and fill empty results with None
map(None, *[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e',)])
[ "python.library.functions#map" ]
map(None, *[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e',)])
conala
1024847-42
Add key "mynewkey" to dictionary `d` with value "mynewvalue"
d['mynewkey'] = 'mynewvalue'
[]
VAR_STR['VAR_STR'] = 'VAR_STR'
conala
1024847-44
Add key 'a' to dictionary `data` with value 1
data.update({'a': 1, })
[ "python.library.stdtypes#dict.update" ]
VAR_STR.update({'VAR_STR': 1})
conala
1024847-96
Add key 'a' to dictionary `data` with value 1
data.update(dict(a=1))
[ "python.library.stdtypes#dict", "python.library.stdtypes#dict.update" ]
VAR_STR.update(dict(VAR_STR=1))
conala
1024847-96
Add key 'a' to dictionary `data` with value 1
data.update(a=1)
[ "python.library.stdtypes#dict", "python.library.stdtypes#dict.update" ]
VAR_STR.update(VAR_STR=1)
conala
35837346-37
find maximal value in matrix `matrix`
max([max(i) for i in matrix])
[ "python.library.functions#max" ]
max([max(i) for i in VAR_STR])
conala
20457038-38
Round number `answer` to 2 precision after the decimal point
answer = str(round(answer, 2))
[ "python.library.functions#round", "python.library.stdtypes#str" ]
VAR_STR = str(round(VAR_STR, 2))
conala
2890896-87
extract ip address from an html string
ip = re.findall('[0-9]+(?:\\.[0-9]+){3}', s)
[ "python.library.re#re.findall" ]
ip = re.findall('[0-9]+(?:\\.[0-9]+){3}', s)
conala
2545397-74
append each line in file `myfile` into a list
[x for x in myfile.splitlines() if x != '']
[ "python.library.stdtypes#str.splitlines" ]
[x for x in VAR_STR.splitlines() if x != '']
conala
2545397-42
Get a list of integers `lst` from a file `filename.txt`
lst = map(int, open('filename.txt').readlines())
[ "python.library.functions#map", "python.library.urllib.request#open", "python.library.io#io.IOBase.readlines" ]
VAR_STR = map(int, open('VAR_STR').readlines())
conala
16330838-72
Python split a string using regex
re.findall('(.+?):(.+?)\\b ?', text)
[ "python.library.re#re.findall" ]
re.findall('(.+?):(.+?)\\b ?', text)
conala
7378180-24
generate all 2-element subsets of tuple `(1, 2, 3)`
list(itertools.combinations((1, 2, 3), 2))
[ "python.library.itertools#itertools.combinations", "python.library.functions#list" ]
list(itertools.combinations((VAR_STR), 2))
conala
4842956-95
Get a new list `list2`by removing empty list from a list of lists `list1`
list2 = [x for x in list1 if x != []]
[]
VAR_STR = [x for x in VAR_STR if x != []]
conala
4842956-35
Create `list2` to contain the lists from list `list1` excluding the empty lists from `list1`
list2 = [x for x in list1 if x]
[]
VAR_STR = [x for x in VAR_STR if x]
conala
17284947-68
get all text that is not enclosed within square brackets in string `example_str`
re.findall('(.*?)\\[.*?\\]', example_str)
[ "python.library.re#re.findall" ]
re.findall('(.*?)\\[.*?\\]', VAR_STR)
conala
17284947-88
Use a regex to get all text in a string `example_str` that is not surrounded by square brackets
re.findall('(.*?)(?:\\[.*?\\]|$)', example_str)
[ "python.library.re#re.findall" ]
re.findall('(.*?)(?:\\[.*?\\]|$)', VAR_STR)
conala
14182339-77
get whatever is between parentheses as a single match, and any char outside as an individual match in string '(zyx)bc'
re.findall('\\(.+?\\)|\\w', '(zyx)bc')
[ "python.library.re#re.findall" ]
re.findall('\\(.+?\\)|\\w', 'VAR_STR')
conala
14182339-26
match regex '\\((.*?)\\)|(\\w)' with string '(zyx)bc'
re.findall('\\((.*?)\\)|(\\w)', '(zyx)bc')
[ "python.library.re#re.findall" ]
re.findall('VAR_STR', 'VAR_STR')
conala
14182339-43
match multiple regex patterns with the alternation operator `|` in a string `(zyx)bc`
re.findall('\\(.*?\\)|\\w', '(zyx)bc')
[ "python.library.re#re.findall" ]
re.findall('\\(.*?\\)|\\w', 'VAR_STR')
conala
7126916-65
formate each string cin list `elements` into pattern '%{0}%'
elements = ['%{0}%'.format(element) for element in elements]
[ "python.library.functions#format" ]
VAR_STR = ['VAR_STR'.format(element) for element in VAR_STR]
conala
18453566-41
get list of values from dictionary 'mydict' w.r.t. list of keys 'mykeys'
[mydict[x] for x in mykeys]
[]
[VAR_STR[x] for x in VAR_STR]
conala
12692135-58
convert list `[('Name', 'Joe'), ('Age', 22)]` into a dictionary
dict([('Name', 'Joe'), ('Age', 22)])
[ "python.library.stdtypes#dict" ]
dict([VAR_STR])
conala
14401047-34
average each two columns of array `data`
data.reshape(-1, j).mean(axis=1).reshape(data.shape[0], -1)
[ "numpy.reference.generated.numpy.reshape", "python.library.statistics#statistics.mean" ]
VAR_STR.reshape(-1, j).mean(axis=1).reshape(VAR_STR.shape[0], -1)
conala
18886596-10
double backslash escape all double quotes in string `s`
print(s.encode('unicode-escape').replace('"', '\\"'))
[ "python.library.stdtypes#str.encode", "python.library.stdtypes#str.replace" ]
print(VAR_STR.encode('unicode-escape').replace('"', '\\"'))
conala
5932059-97
split a string into a list of words and whitespace
re.split('(\\W+)', s)
[ "python.library.re#re.split" ]
re.split('(\\W+)', s)
conala