rewritten_intent
stringlengths 4
183
⌀ | intent
stringlengths 11
122
| snippet
stringlengths 2
232
| question_id
int64 1.48k
42.8M
|
---|---|---|---|
Concatenate elements of a list 'x' of multiple integers to a single integer | How to convert a list of multiple integers into a single integer? | sum(d * 10 ** i for i, d in enumerate(x[::-1])) | 41,067,960 |
convert a list of integers into a single integer | How to convert a list of multiple integers into a single integer? | r = int(''.join(map(str, x))) | 41,067,960 |
convert a DateTime string back to a DateTime object of format '%Y-%m-%d %H:%M:%S.%f' | how to convert a datetime string back to datetime object? | datetime.strptime('2010-11-13 10:33:54.227806', '%Y-%m-%d %H:%M:%S.%f') | 4,170,655 |
get the average of a list values for each key in dictionary `d`) | Averaging the values in a dictionary based on the key | [(i, sum(j) / len(j)) for i, j in list(d.items())] | 29,565,452 |
zip two lists `[1, 2]` and `[3, 4]` into a list of two tuples containing elements at the same index in each list | zip lists in python | zip([1, 2], [3, 4]) | 13,704,860 |
prepend string 'hello' to all items in list 'a' | Prepend the same string to all items in a list | ['hello{0}'.format(i) for i in a] | 13,331,419 |
regex for repeating words in a string `s` | regex for repeating words in a string in Python | re.sub('(?<!\\S)((\\S+)(?:\\s+\\2))(?:\\s+\\2)+(?!\\S)', '\\1', s) | 25,474,338 |
normalize a pandas dataframe `df` by row | Normalizing a pandas DataFrame by row | df.div(df.sum(axis=1), axis=0) | 18,594,469 |
swap values in a tuple/list inside a list `mylist` | swap values in a tuple/list inside a list in python? | map(lambda t: (t[1], t[0]), mylist) | 13,384,841 |
Swap values in a tuple/list in list `mylist` | swap values in a tuple/list inside a list in python? | [(t[1], t[0]) for t in mylist] | 13,384,841 |
null | Find next sibling element in Python Selenium? | driver.find_element_by_xpath("//p[@id, 'one']/following-sibling::p") | 23,887,592 |
find all occurrences of the pattern '\\[[^\\]]*\\]|\\([^\\)]*\\)|"[^"]*"|\\S+' within `strs` | Python splitting string by parentheses | re.findall('\\[[^\\]]*\\]|\\([^\\)]*\\)|"[^"]*"|\\S+', strs) | 17,352,321 |
generate the combinations of 3 from a set `{1, 2, 3, 4}` | What's the most memory efficient way to generate the combinations of a set in python? | print(list(itertools.combinations({1, 2, 3, 4}, 3))) | 10,115,967 |
add multiple columns `hour`, `weekday`, `weeknum` to pandas data frame `df` from lambda function `lambdafunc` | Add Multiple Columns to Pandas Dataframe from Function | df[['hour', 'weekday', 'weeknum']] = df.apply(lambdafunc, axis=1) | 30,026,815 |
BeautifulSoup search string 'Elsie' inside tag 'a' | BeautifulSoup - search by text inside a tag | soup.find_all('a', string='Elsie') | 31,958,637 |
Convert a datetime object `my_datetime` into readable format `%B %d, %Y` | How do I turn a python datetime into a string, with readable format date? | my_datetime.strftime('%B %d, %Y') | 2,158,347 |
parse string `s` to int when string contains a number | Parse string to int when string contains a number + extra characters | int(''.join(c for c in s if c.isdigit())) | 17,888,152 |
add dictionary `{'class': {'section': 5}}` to key 'Test' of dictionary `dic` | adding new key inside a new key and assigning value in python dictionary | dic['Test'].update({'class': {'section': 5}}) | 37,855,490 |
transforming the string `s` into dictionary | Transforming the string representation of a dictionary into a real dictionary | dict(map(int, x.split(':')) for x in s.split(',')) | 4,127,344 |
null | How to select element with Selenium Python xpath | driver.find_element_by_xpath("//div[@id='a']//a[@class='click']") | 19,035,186 |
find rows matching `(0,1)` in a 2 dimensional numpy array `vals` | Find matching rows in 2 dimensional numpy array | np.where((vals == (0, 1)).all(axis=1)) | 25,823,608 |
null | How to delete a record in Django models? | SomeModel.objects.filter(id=id).delete() | 3,805,958 |
build a dictionary containing the conversion of each list in list `[['two', 2], ['one', 1]]` to a key/value pair as its items | python convert list to dictionary | dict([['two', 2], ['one', 1]]) | 6,900,955 |
convert list `l` to dictionary having each two adjacent elements as key/value pair | python convert list to dictionary | dict(zip(l[::2], l[1::2])) | 6,900,955 |
assign float 9.8 to variable `GRAVITY` | how to set global const variables in python | GRAVITY = 9.8 | 18,224,991 |
separate numbers from characters in string "30m1000n20m" | How to use regular expression to separate numbers and characters in strings like "30M1000N20M" | re.findall('(([0-9]+)([A-Z]))', '20M10000N80M') | 15,103,484 |
separate numbers and characters in string '20M10000N80M' | How to use regular expression to separate numbers and characters in strings like "30M1000N20M" | re.findall('([0-9]+|[A-Z])', '20M10000N80M') | 15,103,484 |
separate numbers and characters in string '20M10000N80M' | How to use regular expression to separate numbers and characters in strings like "30M1000N20M" | re.findall('([0-9]+)([A-Z])', '20M10000N80M') | 15,103,484 |
Get a list of words from a string `Hello world, my name is...James the 2nd!` removing punctuation | Extracting words from a string, removing punctuation and returning a list with separated words in Python | re.compile('\\w+').findall('Hello world, my name is...James the 2nd!') | 7,633,274 |
Convert string '03:55' into datetime.time object | Convert string into datetime.time object | datetime.datetime.strptime('03:55', '%H:%M').time() | 14,295,673 |
request url 'https://www.reporo.com/' without verifying SSL certificates | Python Requests getting SSLerror | requests.get('https://www.reporo.com/', verify=False) | 28,667,684 |
Extract values not equal to 0 from numpy array `a` | removing data from a numpy.array | a[a != 0] | 5,927,180 |
map two lists `keys` and `values` into a dictionary | Map two lists into a dictionary in Python | new_dict = {k: v for k, v in zip(keys, values)} | 209,840 |
map two lists `keys` and `values` into a dictionary | Map two lists into a dictionary in Python | dict((k, v) for k, v in zip(keys, values)) | 209,840 |
map two lists `keys` and `values` into a dictionary | Map two lists into a dictionary in Python | dict([(k, v) for k, v in zip(keys, values)]) | 209,840 |
find the string matches within parenthesis from a string `s` using regex | Get the string within brackets in Python | m = re.search('\\[(\\w+)\\]', s) | 8,569,201 |
Enable the SO_REUSEADDR socket option in socket object `s` to fix the error `only one usage of each socket address is normally permitted` | Python server "Only one usage of each socket address is normally permitted" | s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1) | 12,362,542 |
append the sum of each tuple pair in the grouped list `list1` and list `list2` elements to list `list3` | How do i add two lists' elements into one list? | list3 = [(a + b) for a, b in zip(list1, list2)] | 11,703,064 |
converting hex string `s` to its integer representations | Python - Converting Hex to INT/CHAR | [ord(c) for c in s.decode('hex')] | 7,595,148 |
sort list `student_tuples` by second element of each tuple in ascending and third element of each tuple in descending | How to sort in decreasing value first then increasing in second value | print(sorted(student_tuples, key=lambda t: (-t[2], t[0]))) | 16,537,636 |
get list of duplicated elements in range of 3 | Repeating elements in list comprehension | [y for x in range(3) for y in [x, x]] | 3,925,465 |
read the contents of the file 'file.txt' into `txt` | Doc, rtf and txt reader in python | txt = open('file.txt').read() | 3,278,850 |
divide each element in list `myList` by integer `myInt` | How do you divide each element in a list by an int? | myList[:] = [(x / myInt) for x in myList] | 8,244,915 |
null | python: dots in the name of variable in a format string | """Name: {0[person.name]}""".format({'person.name': 'Joe'}) | 7,934,620 |
replace white spaces in dataframe `df` with '_' | How to replace the white space in a string in a pandas dataframe? | df.replace(' ', '_', regex=True) | 42,462,530 |
convert date `my_date` to datetime | Python: most efficient way to convert date to datetime | datetime.datetime.combine(my_date, datetime.time.min) | 15,661,013 |
convert tuple `tst` to string `tst2` | Tuple to string | tst2 = str(tst) | 3,886,669 |
get modified time of file `file` | get file creation & modification date/times in | time.ctime(os.path.getmtime(file)) | 237,079 |
get creation time of file `file` | get file creation & modification date/times in | time.ctime(os.path.getctime(file)) | 237,079 |
get modification time of file `filename` | get file creation & modification date/times in | t = os.path.getmtime(filename) | 237,079 |
get modification time of file `path` | get file creation & modification date/times in | os.path.getmtime(path) | 237,079 |
get modified time of file `file` | get file creation & modification date/times in | print(('last modified: %s' % time.ctime(os.path.getmtime(file)))) | 237,079 |
get the creation time of file `file` | get file creation & modification date/times in | print(('created: %s' % time.ctime(os.path.getctime(file)))) | 237,079 |
get the creation time of file `path_to_file` | get file creation & modification date/times in | return os.path.getctime(path_to_file) | 237,079 |
execute os command ''TASKKILL /F /IM firefox.exe'' | How to Close a program using python? | os.system('TASKKILL /F /IM firefox.exe') | 5,625,524 |
split string `string` on whitespaces using a generator | Is there a generator version of `string.split()` in Python? | return (x.group(0) for x in re.finditer("[A-Za-z']+", string)) | 3,862,010 |
Unpack each value in list `x` to its placeholder '%' in string '%.2f' | Using Python String Formatting with Lists | """, """.join(['%.2f'] * len(x)) | 7,568,627 |
match regex pattern '(\\d+(\\.\\d+)?)' with string '3434.35353' | How to use regex with optional characters in python? | print(re.match('(\\d+(\\.\\d+)?)', '3434.35353').group(1)) | 9,891,814 |
replace parentheses and all data within it with empty string '' in column 'name' of dataframe `df` | How to remove parentheses and all data within using Pandas/Python? | df['name'].str.replace('\\(.*\\)', '') | 20,894,525 |
create a list `result` containing elements form list `list_a` if first element of list `list_a` is in list `list_b` | Python: filter list of list with another list | result = [x for x in list_a if x[0] in list_b] | 18,448,469 |
generate all possible string permutations of each two elements in list `['hel', 'lo', 'bye']` | Generate all possible strings from a list of token | print([''.join(a) for a in combinations(['hel', 'lo', 'bye'], 2)]) | 4,059,550 |
get a list of items form nested list `li` where third element of each item contains string 'ar' | python how to search an item in a nested list | [x for x in li if 'ar' in x[2]] | 6,889,785 |
Sort lists in the list `unsorted_list` by the element at index 3 of each list | Python - How to sort a list of lists by the fourth element in each list? | unsorted_list.sort(key=lambda x: x[3]) | 17,555,218 |
Log message 'test' on the root logger. | Python logging typeerror | logging.info('test') | 18,292,500 |
Return a subplot axes positioned by the grid definition `1,1,1` using matpotlib | How to make several plots on a single page using matplotlib? | fig.add_subplot(1, 1, 1) | 1,358,977 |
Sort dictionary `x` by value in ascending order | Sort a Python dictionary by value | sorted(list(x.items()), key=operator.itemgetter(1)) | 613,183 |
Sort dictionary `dict1` by value in ascending order | Sort a Python dictionary by value | sorted(dict1, key=dict1.get) | 613,183 |
Sort dictionary `d` by value in descending order | Sort a Python dictionary by value | sorted(d, key=d.get, reverse=True) | 613,183 |
Sort dictionary `d` by value in ascending order | Sort a Python dictionary by value | sorted(list(d.items()), key=(lambda x: x[1])) | 613,183 |
elementwise product of 3d arrays `A` and `B` | Numpy elementwise product of 3d array | np.einsum('ijk,ikl->ijl', A, B) | 31,957,364 |
Print a string `card` with string formatting | print variable and a string in python | print('I have: {0.price}'.format(card)) | 14,041,791 |
Write a comment `# Data for Class A\n` to a file object `f` | How can I add a comment to a YAML file in Python | f.write('# Data for Class A\n') | 30,994,370 |
move the last item in list `a` to the beginning | How do I move the last item in a list to the front in python? | a = a[-1:] + a[:-1] | 6,490,560 |
Parse DateTime object `datetimevariable` using format '%Y-%m-%d' | python - convert datetime to varchar/string | datetimevariable.strftime('%Y-%m-%d') | 40,173,569 |
Normalize line ends in a string 'mixed' | What's the most pythonic way of normalizing lineends in a string? | mixed.replace('\r\n', '\n').replace('\r', '\n') | 1,749,466 |
find the real user home directory using python | How to find the real user home directory using python? | os.path.expanduser('~user') | 2,668,909 |
index a list `L` with another list `Idx` | In Python, how do I index a list with another list? | T = [L[i] for i in Idx] | 1,012,185 |
get a list of words `words` of a file 'myfile' | Iterate through words of a file in Python | words = open('myfile').read().split() | 7,745,260 |
Get a list of lists with summing the values of the second element from each list of lists `data` | Summing 2nd list items in a list of lists of lists | [[sum([x[1] for x in i])] for i in data] | 37,619,348 |
summing the second item in a list of lists of lists | Summing 2nd list items in a list of lists of lists | [sum([x[1] for x in i]) for i in data] | 37,619,348 |
sort objects in `Articles` in descending order of counts of `likes` | Django order by highest number of likes | Article.objects.annotate(like_count=Count('likes')).order_by('-like_count') | 35,097,130 |
return a DateTime object with the current UTC date | How to convert datetime.date.today() to UTC time? | today = datetime.datetime.utcnow().date() | 27,587,127 |
create a list containing the multiplication of each elements at the same index of list `lista` and list `listb` | How to perform element-wise multiplication of two lists in Python? | [(a * b) for a, b in zip(lista, listb)] | 10,271,484 |
fetch smilies matching regex pattern '(?::|;|=)(?:-)?(?:\\)|\\(|D|P)' in string `s` | Capturing emoticons using regular expression in python | re.findall('(?::|;|=)(?:-)?(?:\\)|\\(|D|P)', s) | 14,571,103 |
match the pattern '[:;][)(](?![)(])' to the string `str` | Capturing emoticons using regular expression in python | re.match('[:;][)(](?![)(])', str) | 14,571,103 |
convert a list of objects `list_name` to json string `json_string` | List of objects to JSON with Python | json_string = json.dumps([ob.__dict__ for ob in list_name]) | 26,033,239 |
create a list `listofzeros` of `n` zeros | List of zeros in python | listofzeros = [0] * n | 8,528,178 |
decode the string 'stringnamehere' to UTF-8 | python: how to convert a string to utf-8 | stringnamehere.decode('utf-8', 'ignore') | 4,182,603 |
Match regex pattern '((?:A|B|C)D)' on string 'BDE' | Python regex - Ignore parenthesis as indexing? | re.findall('((?:A|B|C)D)', 'BDE') | 11,985,628 |
Create a key `key` if it does not exist in dict `dic` and append element `value` to value. | Python dict how to create key or append an element to key? | dic.setdefault(key, []).append(value) | 12,905,999 |
Get the value of the minimum element in the second column of array `a` | Finding the minimum value in a numpy array and the corresponding values for the rest of that array's row | a[np.argmin(a[:, (1)])] | 14,956,683 |
extend dictionary `a` with key/value pairs of dictionary `b` | Python "extend" for a dictionary | a.update(b) | 577,234 |
removing key values pairs with key 'mykey1' from a list of dictionaries `mylist` | Removing key values pairs from a list of dictionaries | [{k: v for k, v in d.items() if k != 'mykey1'} for d in mylist] | 13,254,241 |
null | Removing key values pairs from a list of dictionaries | [dict((k, v) for k, v in d.items() if k != 'mykey1') for d in mylist] | 13,254,241 |
create 3 by 3 matrix of random numbers | Simple way to create matrix of random numbers | numpy.random.random((3, 3)) | 15,451,958 |
make new column 'C' in panda dataframe by adding values from other columns 'A' and 'B' | Make new column in Panda dataframe by adding values from other columns | df['C'] = df['A'] + df['B'] | 34,023,918 |
create a list of values from the dictionary `programs` that have a key with a case insensitive match to 'new york' | Find dictionary items whose key matches a substring | [value for key, value in list(programs.items()) if 'new york' in key.lower()] | 10,484,261 |
append a path `/path/to/main_folder` in system path | Import module in another directory from a "parallel" sub-directory | sys.path.append('/path/to/main_folder') | 9,153,527 |
get all digits in a string `s` after a '[' character | Regex for getting all digits in a string after a character | re.findall('\\d+(?=[^[]+$)', s) | 34,338,341 |
python pickle/unpickle a list to/from a file 'afile' | Python pickle/unpickle a list to/from a file | pickle.load(open('afile', 'rb')) | 18,229,082 |