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 |
---|---|---|---|---|---|
15103484-24 | 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 |
2052390-4 | manually throw/raise a `ValueError` exception with the message 'A very specific bad thing happened' | raise ValueError('A very specific bad thing happened') | [
"python.library.exceptions#ValueError"
] | raise VAR_STR('VAR_STR') | conala |
2052390-88 | throw an exception "I know Python!" | raise Exception('I know Python!') | [
"python.library.exceptions#Exception"
] | raise Exception('VAR_STR') | conala |
2052390-69 | Manually throw an exception "I know python!" | raise Exception('I know python!') | [
"python.library.exceptions#Exception"
] | raise Exception('VAR_STR') | conala |
2052390-39 | throw a ValueError with message 'represents a hidden bug, do not catch this' | raise ValueError('represents a hidden bug, do not catch this') | [
"python.library.exceptions#ValueError"
] | raise ValueError('VAR_STR') | conala |
2052390-95 | throw an Exception with message 'This is the exception you expect to handle' | raise Exception('This is the exception you expect to handle') | [
"python.library.exceptions#Exception"
] | raise Exception('VAR_STR') | conala |
2052390-76 | throw a value error with message 'A very specific bad thing happened', 'foo', 'bar', 'baz' | raise ValueError('A very specific bad thing happened') | [
"python.library.exceptions#ValueError"
] | raise ValueError('VAR_STR') | conala |
2052390-99 | throw a runtime error with message 'specific message' | raise RuntimeError('specific message') | [
"python.library.exceptions#RuntimeError"
] | raise RuntimeError('VAR_STR') | conala |
2052390-32 | throw an assertion error with message "Unexpected value of 'distance'!", distance | raise AssertionError("Unexpected value of 'distance'!", distance) | [
"python.library.exceptions#AssertionError"
] | raise AssertionError('VAR_STR', distance) | conala |
12897374-47 | remove duplicates from list `myset` | mynewlist = list(myset) | [
"python.library.functions#list"
] | mynewlist = list(VAR_STR) | conala |
12897374-66 | get unique values from the list `['a', 'b', 'c', 'd']` | set(['a', 'b', 'c', 'd']) | [
"python.library.stdtypes#set"
] | set([VAR_STR]) | conala |
35005907-50 | split string `s` based on white spaces | re.findall('\\s+|\\S+', s) | [
"python.library.re#re.findall"
] | re.findall('\\s+|\\S+', VAR_STR) | conala |
2636755-57 | convert a hex string `x` to string | y = str(int(x, 16)) | [
"python.library.functions#int",
"python.library.stdtypes#str"
] | y = str(int(VAR_STR, 16)) | conala |
3925465-40 | get list of duplicated elements in range of 3 | [y for x in range(3) for y in [x, x]] | [
"python.library.functions#range"
] | [y for x in range(3) for y in [x, x]] | conala |
9053260-30 | remove elements in list `b` from list `a` | [x for x in a if x not in b] | [] | [x for x in VAR_STR if x not in VAR_STR] | conala |
6667201-23 | create a list `matrix` containing 5 lists, each of 5 items all set to 0 | matrix = [([0] * 5) for i in range(5)] | [
"python.library.functions#range"
] | VAR_STR = [([0] * 5) for i in range(5)] | conala |
3471999-53 | interleave the elements of two lists `a` and `b` | [j for i in zip(a, b) for j in i] | [
"python.library.functions#zip"
] | [j for i in zip(VAR_STR, VAR_STR) for j in i] | conala |
3471999-1 | merge two lists `a` and `b` into a single list | [j for i in zip(a, b) for j in i] | [
"python.library.functions#zip"
] | [j for i in zip(VAR_STR, VAR_STR) for j in i] | conala |
7831371-34 | SQLite get a list of column names from cursor object `cursor` | names = list(map(lambda x: x[0], cursor.description)) | [
"python.library.functions#map",
"python.library.functions#list"
] | names = list(map(lambda x: x[0], VAR_STR.description)) | conala |
27218543-39 | select the last business day of the month for each month in 2014 in pandas | pd.date_range('1/1/2014', periods=12, freq='BM') | [
"pandas.reference.api.pandas.date_range"
] | pd.date_range('1/1/2014', periods=12, freq='BM') | conala |
42142756-73 | rename `last` row index label in dataframe `df` to `a` | df = df.rename(index={last: 'a'}) | [
"pandas.reference.api.pandas.dataframe.rename"
] | VAR_STR = VAR_STR.rename(index={VAR_STR: 'VAR_STR'}) | conala |
3428769-74 | Finding the largest delta between two integers in a list in python | max(abs(x - y) for x, y in zip(values[1:], values[:-1])) | [
"python.library.functions#zip",
"python.library.functions#abs",
"python.library.functions#max"
] | max(abs(x - y) for x, y in zip(values[1:], values[:-1])) | conala |
510348-43 | delay for "5" seconds | time.sleep(5) | [
"python.library.time#time.sleep"
] | time.sleep(5) | conala |
510348-64 | make a 60 seconds time delay | time.sleep(60) | [
"python.library.time#time.sleep"
] | time.sleep(60) | conala |
510348-96 | make a 0.1 seconds time delay | sleep(0.1) | [
"python.library.time#time.sleep"
] | sleep(0.1) | conala |
510348-83 | make a 60 seconds time delay | time.sleep(60) | [
"python.library.time#time.sleep"
] | time.sleep(60) | conala |
510348-35 | make a 0.1 seconds time delay | time.sleep(0.1) | [
"python.library.time#time.sleep"
] | time.sleep(0.1) | conala |
3505831-69 | pads string '5' on the left with 1 zero | print('{0}'.format('5'.zfill(2))) | [
"python.library.functions#format",
"python.library.stdtypes#str.zfill"
] | print('{0}'.format('VAR_STR'.zfill(2))) | conala |
12974474-46 | Unzip a list of tuples `l` into a list of lists | zip(*l) | [
"python.library.functions#zip"
] | zip(*VAR_STR) | conala |
27436748-64 | reduce the first element of list of strings `data` to a string, separated by '.' | print('.'.join([item[0] for item in data])) | [
"python.library.stdtypes#str.join"
] | print('VAR_STR'.join([item[0] for item in VAR_STR])) | conala |
12440342-92 | get the first element of each tuple from a list of tuples `G` | [x[0] for x in G] | [] | [x[0] for x in VAR_STR] | conala |
818949-51 | create list `changed_list ` containing elements of list `original_list` whilst converting strings containing digits to integers | changed_list = [(int(f) if f.isdigit() else f) for f in original_list] | [
"python.library.functions#int",
"python.library.stdtypes#str.isdigit"
] | VAR_STR = [(int(f) if f.isdigit() else f) for f in VAR_STR] | conala |
25440008-98 | flatten a dataframe df to a list | df.values.flatten() | [] | df.values.flatten() | conala |
306400-38 | randomly select an item from list `foo` | random.choice(foo) | [
"python.library.random#random.choice"
] | random.choice(VAR_STR) | conala |
940822-75 | regular expression match nothing | re.compile('$^') | [
"python.library.re#re.compile"
] | re.compile('$^') | conala |
940822-88 | regular expression syntax for not to match anything | re.compile('.\\A|.\\A*|.\\A+') | [
"python.library.re#re.compile"
] | re.compile('.\\A|.\\A*|.\\A+') | conala |
940822-67 | create a regular expression object with a pattern that will match nothing | re.compile('a^') | [
"python.library.re#re.compile"
] | re.compile('a^') | conala |
34696853-20 | convert a list of strings `lst` to list of integers | [map(int, sublist) for sublist in lst] | [
"python.library.functions#map"
] | [map(int, sublist) for sublist in VAR_STR] | conala |
34696853-89 | convert strings in list-of-lists `lst` to ints | [[int(x) for x in sublist] for sublist in lst] | [
"python.library.functions#int"
] | [[int(x) for x in sublist] for sublist in VAR_STR] | conala |
5501641-12 | create a list with the characters of a string `5+6` | list('5+6') | [
"python.library.functions#list"
] | list('VAR_STR') | conala |
11573817-17 | How to download a file via FTP with Python ftplib | ftp.retrbinary('RETR %s' % filename, file.write) | [
"python.library.ftplib#ftplib.FTP.retrbinary"
] | ftp.retrbinary('RETR %s' % filename, file.write) | conala |
29422691-3 | print the number of occurences of not `none` in a list `lst` in Python 2 | print(len([x for x in lst if x is not None])) | [
"python.library.functions#len"
] | print(len([x for x in VAR_STR if x is not None])) | conala |
9339630-98 | encode string `s` to utf-8 code | s.encode('utf8') | [
"python.library.stdtypes#str.encode"
] | VAR_STR.encode('utf8') | conala |
24841306-8 | get a sum of 4d array `M` | M.sum(axis=0).sum(axis=0) | [
"python.library.functions#sum"
] | VAR_STR.sum(axis=0).sum(axis=0) | conala |
11932729-43 | sort a python dictionary `a_dict` by element `1` of the value | sorted(list(a_dict.items()), key=lambda item: item[1][1]) | [
"python.library.functions#sorted",
"python.library.functions#list",
"python.library.stdtypes#dict.items"
] | sorted(list(VAR_STR.items()), key=lambda item: item[1][1]) | conala |
10201977-40 | Reverse list `x` | x[::-1] | [] | VAR_STR[::-1] | conala |
4915920-75 | delete an item `thing` in a list `some_list` if it exists | cleaned_list = [x for x in some_list if x is not thing] | [] | cleaned_list = [x for x in VAR_STR if x is not VAR_STR] | conala |
35427814-67 | get the number of all keys in the nested dictionary `dict_list` | len(dict_test) + sum(len(v) for v in dict_test.values()) | [
"python.library.functions#len",
"python.library.functions#sum",
"python.library.stdtypes#dict.values"
] | len(dict_test) + sum(len(v) for v in dict_test.values()) | conala |
6133434-3 | 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)] | [
"python.library.functions#len",
"python.library.functions#range",
"python.library.functions#sum"
] | weekly = [sum(visitors[x:x + 7]) for x in range(0, len(VAR_STR), 7)] | conala |
14743454-13 | Get a list of all keys from dictionary `dictA` where the number of occurrences of value `duck` in that key is more than `1` | [k for k, v in dictA.items() if v.count('duck') > 1] | [
"python.library.stdtypes#dict.items",
"python.library.stdtypes#str.count"
] | [k for k, v in VAR_STR.items() if v.count('VAR_STR') > 1] | conala |
29558007-37 | generate a list of consecutive integers from 0 to 8 | list(range(9)) | [
"python.library.functions#range",
"python.library.functions#list"
] | list(range(9)) | conala |
5106228-78 | getting every possible combination of two elements in a list | list(itertools.combinations([1, 2, 3, 4, 5, 6], 2)) | [
"python.library.itertools#itertools.combinations",
"python.library.functions#list"
] | list(itertools.combinations([1, 2, 3, 4, 5, 6], 2)) | conala |
18312447-81 | split string 'x+13.5*10x-4e1' into tokens | print([i for i in re.split('([\\d.]+|\\W+)', 'x+13.5*10x-4e1') if i]) | [
"python.library.re#re.split"
] | print([i for i in re.split('([\\d.]+|\\W+)', 'VAR_STR') if i]) | conala |
13891559-42 | unpack elements of list `i` as arguments into function `foo` | foo(*i) | [] | VAR_STR(*VAR_STR) | conala |
9470142-61 | remove all square brackets from string 'abcd[e]yth[ac]ytwec' | re.sub('\\[.*?\\]', '', 'abcd[e]yth[ac]ytwec') | [
"python.library.re#re.sub"
] | re.sub('\\[.*?\\]', '', 'VAR_STR') | conala |
15752422-54 | set dataframe `df` index using column 'month' | df.set_index('month') | [
"pandas.reference.api.pandas.dataframe.set_index"
] | VAR_STR.set_index('VAR_STR') | conala |
26640145-30 | get a list of the row names from index of a pandas data frame | list(df.index) | [
"python.library.functions#list"
] | list(df.index) | conala |
26640145-100 | get the row names from index in a pandas data frame | df.index | [] | df.index | conala |
2152898-7 | filtering out strings that contain 'ab' from a list of strings `lst` | [k for k in lst if 'ab' in k] | [] | [k for k in VAR_STR if 'VAR_STR' in k] | conala |
16084642-16 | 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)] | [
"python.library.functions#any",
"python.library.stdtypes#str.isdigit"
] | [x for x in VAR_STR if not any(c.isdigit() for c in x)] | conala |
3227624-52 | get file '~/foo.ini' | config_file = os.path.expanduser('~/foo.ini') | [
"python.library.os.path#os.path.expanduser"
] | config_file = os.path.expanduser('VAR_STR') | conala |
18551752-51 | split string `text` into chunks of 16 characters each | re.findall('.{,16}\\b', text) | [
"python.library.re#re.findall"
] | re.findall('.{,16}\\b', VAR_STR) | conala |
5075247-69 | remove line breaks from string `textblock` using regex | re.sub('(?<=[a-z])\\r?\\n', ' ', textblock) | [
"python.library.re#re.sub"
] | re.sub('(?<=[a-z])\\r?\\n', ' ', VAR_STR) | conala |
16962512-77 | convert scientific notation of variable `a` to decimal | """{:.50f}""".format(float(a[0] / a[1])) | [
"python.library.functions#float",
"python.library.functions#format"
] | """{:.50f}""".format(float(VAR_STR[0] / VAR_STR[1])) | conala |
13717463-67 | create a list containing the indices of elements greater than 4 in list `a` | [i for i, v in enumerate(a) if v > 4] | [
"python.library.functions#enumerate"
] | [i for i, v in enumerate(VAR_STR) if v > 4] | conala |
42098487-14 | split 1d array `a` into 2d array at the last element | np.split(a, [-1]) | [
"numpy.reference.generated.numpy.split"
] | np.split(VAR_STR, [-1]) | conala |
29815129-54 | convert dataframe `df` to list of dictionaries including the index values | df.to_dict('index') | [
"pandas.reference.api.pandas.dataframe.to_dict"
] | VAR_STR.to_dict('index') | conala |
29815129-23 | Create list of dictionaries from pandas dataframe `df` | df.to_dict('records') | [
"pandas.reference.api.pandas.dataframe.to_dict"
] | VAR_STR.to_dict('records') | conala |
15096021-2 | Flatten list `x` | x = [i[0] for i in x] | [] | VAR_STR = [i[0] for i in VAR_STR] | conala |
15096021-36 | convert list `x` into a flat list | y = map(operator.itemgetter(0), x) | [
"python.library.operator#operator.itemgetter",
"python.library.functions#map"
] | y = map(operator.itemgetter(0), VAR_STR) | conala |
15096021-51 | get a list `y` of the first element of every tuple in list `x` | y = [i[0] for i in x] | [] | VAR_STR = [i[0] for i in VAR_STR] | conala |
24082784-99 | Group a pandas data frame by monthly frequenct `M` using groupby | df.groupby(pd.TimeGrouper(freq='M')) | [
"pandas.reference.api.pandas.dataframe.groupby"
] | df.groupby(pd.TimeGrouper(freq='VAR_STR')) | conala |
2153444-1 | Find average of a nested list `a` | a = [(sum(x) / len(x)) for x in zip(*a)] | [
"python.library.functions#zip",
"python.library.functions#len",
"python.library.functions#sum"
] | VAR_STR = [(sum(x) / len(x)) for x in zip(*VAR_STR)] | conala |
6879364-89 | Get the age of directory (or file) `/tmp` in seconds. | print(os.path.getmtime('/tmp')) | [
"python.library.os.path#os.path.getmtime"
] | print(os.path.getmtime('VAR_STR')) | conala |
715417-70 | Convert string to boolean from defined set of strings | s in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh'] | [] | s in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh'] | conala |
11921649-79 | Format string `hello {name}, how are you {name}, welcome {name}` to be interspersed by `name` three times, specifying the value as `john` only once | """hello {name}, how are you {name}, welcome {name}""".format(name='john') | [
"python.library.functions#format"
] | """VAR_STR""".format(VAR_STR='VAR_STR') | conala |
3731426-92 | divide the members of a list `conversions` by the corresponding members of another list `trials` | [(c / t) for c, t in zip(conversions, trials)] | [
"python.library.functions#zip"
] | [(c / t) for c, t in zip(VAR_STR, VAR_STR)] | conala |
8936030-9 | searche in HTML string for elements that have text 'Python' | soup.body.findAll(text='Python') | [
"python.library.re#re.findall"
] | soup.body.findAll(text='VAR_STR') | conala |
8936030-35 | BeautifulSoup find string 'Python Jobs' in HTML body `body` | soup.body.findAll(text='Python Jobs') | [
"python.library.re#re.findall"
] | soup.VAR_STR.findAll(text='VAR_STR') | conala |
36113747-21 | Initialize a list `a` with `10000` items and each item's value `0` | a = [0] * 10000 | [] | VAR_STR = [0] * 10000 | conala |
17555218-63 | Sort lists in the list `unsorted_list` by the element at index 3 of each list | unsorted_list.sort(key=lambda x: x[3]) | [
"python.library.stdtypes#list.sort"
] | VAR_STR.sort(key=lambda x: x[3]) | conala |
40682209-98 | Replace NaN values in column 'value' with the mean of data in column 'group' of dataframe `df` | df[['value']].fillna(df.groupby('group').transform('mean')) | [
"pandas.reference.api.pandas.dataframe.groupby",
"pandas.reference.api.pandas.dataframe.fillna",
"pandas.reference.api.pandas.dataframe.transform"
] | VAR_STR[['VAR_STR']].fillna(VAR_STR.groupby('VAR_STR').transform('mean')) | conala |
24722212-6 | add a path `/path/to/2014_07_13_test` to system path | sys.path.append('/path/to/2014_07_13_test') | [
"numpy.reference.generated.numpy.append"
] | sys.path.append('VAR_STR') | conala |
16096754-83 | remove None value from list `L` | [x for x in L if x is not None] | [] | [x for x in VAR_STR if x is not None] | conala |
21261330-82 | Split string with comma (,) and remove whitespace from a string 'my_string' | [item.strip() for item in my_string.split(',')] | [
"python.library.stdtypes#str.strip",
"python.library.stdtypes#str.split"
] | [item.strip() for item in VAR_STR.split(',')] | conala |
3718657-91 | get current script directory | os.path.dirname(os.path.abspath(__file__)) | [
"python.library.os.path#os.path.dirname",
"python.library.os.path#os.path.abspath"
] | os.path.dirname(os.path.abspath(__file__)) | conala |
11985628-48 | Match regex pattern '((?:A|B|C)D)' on string 'BDE' | re.findall('((?:A|B|C)D)', 'BDE') | [
"python.library.re#re.findall"
] | re.findall('VAR_STR', 'VAR_STR') | conala |
9962293-50 | create list `done` containing permutations of each element in list `[a, b, c, d]` with variable `x` as tuples | done = [(el, x) for el in [a, b, c, d]] | [] | VAR_STR = [(el, VAR_STR) for el in [VAR_STR]] | conala |
17457793-83 | sort a set `s` by numerical value | sorted(s, key=float) | [
"python.library.functions#sorted"
] | sorted(VAR_STR, key=float) | conala |
12323403-99 | How do I find an element that contains specific text in Selenium Webdriver (Python)? | driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]") | [] | driver.find_elements_by_xpath("//*[contains(text(), 'My Button')]") | conala |
11406091-7 | Selecting Element "//li/label/input" followed by text "polishpottery" with Selenium WebDriver `driver` | driver.find_element_by_xpath("//li/label/input[contains(..,'polishpottery')]") | [] | VAR_STR.find_element_by_xpath("//li/label/input[contains(..,'polishpottery')]") | conala |
10020591-5 | Resample dataframe `frame` to resolution of 1 hour `1H` for timeseries index, summing values in the column `radiation` averaging those in column `tamb` | frame.resample('1H').agg({'radiation': np.sum, 'tamb': np.mean}) | [
"pandas.reference.api.pandas.dataframe.agg"
] | VAR_STR.resample('VAR_STR').agg({'VAR_STR': np.sum, 'VAR_STR': np.mean}) | conala |
14050824-40 | sum each element `x` in list `first` with element `y` at the same index in list `second`. | [(x + y) for x, y in zip(first, second)] | [
"python.library.functions#zip"
] | [(VAR_STR + VAR_STR) for VAR_STR, VAR_STR in zip(VAR_STR, VAR_STR)] | conala |
28780956-93 | get the context of a search by keyword 'My keywords' in beautifulsoup `soup` | k = soup.find(text=re.compile('My keywords')).parent.text | [
"python.library.re#re.compile",
"python.library.stdtypes#str.find"
] | k = VAR_STR.find(text=re.compile('VAR_STR')).parent.text | conala |
2587402-45 | sort list `xs` based on the length of its elements | print(sorted(xs, key=len)) | [
"python.library.functions#sorted"
] | print(sorted(VAR_STR, key=len)) | conala |
2587402-28 | sort list `xs` in ascending order of length of elements | xs.sort(lambda x, y: cmp(len(x), len(y))) | [
"python.library.functions#len",
"python.library.filecmp#filecmp.cmp",
"python.library.stdtypes#list.sort"
] | VAR_STR.sort(lambda x, y: cmp(len(x), len(y))) | conala |
2587402-14 | sort list of strings `xs` by the length of string | xs.sort(key=lambda s: len(s)) | [
"python.library.functions#len",
"python.library.stdtypes#list.sort"
] | VAR_STR.sort(key=lambda s: len(s)) | conala |
23914774-64 | Make a dictionary from list `f` which is in the format of four sets of "val, key, val" | {f[i + 1]: [f[i], f[i + 2]] for i in range(0, len(f), 3)} | [
"python.library.functions#len",
"python.library.functions#range"
] | {VAR_STR[i + 1]: [VAR_STR[i], VAR_STR[i + 2]] for i in range(0, len(VAR_STR), 3)} | conala |
5577501-79 | check if string `string` starts with a number | string[0].isdigit() | [
"python.library.stdtypes#str.isdigit"
] | VAR_STR[0].isdigit() | conala |
5577501-18 | Check if string `strg` starts with any of the elements in list ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') | strg.startswith(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')) | [
"python.library.stdtypes#str.startswith"
] | VAR_STR.startswith(('VAR_STR', 'VAR_STR', 'VAR_STR', 'VAR_STR', 'VAR_STR', 'VAR_STR',
'VAR_STR', 'VAR_STR', 'VAR_STR', 'VAR_STR')) | conala |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.