question_id
int64 1.48k
42.8M
| intent
stringlengths 11
122
| rewritten_intent
stringlengths 4
183
⌀ | snippet
stringlengths 2
232
|
---|---|---|---|
4,324,790 | Removing control characters from a string in python | removing control characters from a string `s` | return ''.join(ch for ch in s if unicodedata.category(ch)[0] != 'C') |
28,767,642 | How to compare two lists in python | Compare if each value in list `a` is less than respective index value in list `b` | all(i < j for i, j in zip(a, b)) |
21,350,605 | python selenium click on button | python selenium click on button '.button.c_button.s_button' | driver.find_element_by_css_selector('.button.c_button.s_button').click() |
21,350,605 | python selenium click on button | null | driver.find_element_by_css_selector('.button .c_button .s_button').click() |
6,278,847 | Is it possible to kill a process on Windows from within Python? | kill a process `make.exe` from python script on windows | os.system('taskkill /im make.exe') |
4,552,380 | How to get current date and time from DB using SQLAlchemy | SQLAlchemy select records of columns of table `my_table` in addition to current date column | print(select([my_table, func.current_date()]).execute()) |
4,574,509 | Remove duplicate chars using regex? | remove duplicate characters from string 'ffffffbbbbbbbqqq' | re.sub('([a-z])\\1+', '\\1', 'ffffffbbbbbbbqqq') |
40,196,941 | Regex to remove periods in acronyms? | remove periods inbetween capital letters that aren't immediately preceeded by word character(s) in a string `s` using regular expressions | re.sub('(?<!\\w)([A-Z])\\.', '\\1', s) |
6,372,228 | how to parse a list or string into chunks of fixed length | Get a list of strings `split_text` with fixed chunk size `n` from a string `the_list` | split_list = [the_list[i:i + n] for i in range(0, len(the_list), n)] |
4,338,032 | replacing all regex matches in single line | match string 'this is my string' with regex '\\b(this|string)\\b'
then replace it with regex '<markup>\\1</markup>' | re.sub('\\b(this|string)\\b', '<markup>\\1</markup>', 'this is my string') |
11,361,985 | Output data from all columns in a dataframe in pandas | output data of the first 7 columns of Pandas dataframe | pandas.set_option('display.max_columns', 7) |
11,361,985 | Output data from all columns in a dataframe in pandas | Display maximum output data of columns in dataframe `pandas` that will fit into the screen | pandas.set_option('display.max_columns', None) |
12,307,099 | Modifying a subset of rows in a pandas dataframe | set the value in column 'B' to NaN if the corresponding value in column 'A' is equal to 0 in pandas dataframe `df` | df.ix[df.A == 0, 'B'] = np.nan |
11,406,091 | Selecting Element followed by text with Selenium WebDriver | Selecting Element "//li/label/input" followed by text "polishpottery" with Selenium WebDriver `driver` | driver.find_element_by_xpath("//li/label/input[contains(..,'polishpottery')]") |
861,190 | Ordering a list of dictionaries in python | Sort a list of dictionaries `mylist` by keys "weight" and "factor" | mylist.sort(key=operator.itemgetter('weight', 'factor')) |
861,190 | Ordering a list of dictionaries in python | ordering a list of dictionaries `mylist` by elements 'weight' and 'factor' | mylist.sort(key=lambda d: (d['weight'], d['factor'])) |
14,986,218 | From a list of lists to a dictionary | 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} |
4,690,094 | Sorting dictionary keys based on their values | sort keys of dictionary 'd' based on their values | sorted(d, key=lambda k: d[k][1]) |
2,742,784 | Python: How to round 123 to 100 instead of 100.0? | round 123 to 100 | int(round(123, -2)) |
1,348,026 | How do I create a file in python without overwriting an existing file | create file 'x' if file 'x' does not exist | fd = os.open('x', os.O_WRONLY | os.O_CREAT | os.O_EXCL) |
40,535,203 | How to slice a list of strings with space delimiter? | get a list of last trailing words from another list of strings`Original_List` | new_list = [x.split()[-1] for x in Original_List] |
931,092 | Reverse a string | Reverse a string 'hello world' | 'hello world'[::(-1)] |
931,092 | Reverse a string | Reverse list `s` | s[::(-1)] |
931,092 | Reverse a string | Reverse string 'foo' | ''.join(reversed('foo')) |
931,092 | Reverse a string | Reverse a string `string` | ''.join(reversed(string)) |
931,092 | Reverse a string | Reverse a string "foo" | 'foo'[::(-1)] |
931,092 | Reverse a string | Reverse a string `a_string` | a_string[::(-1)] |
931,092 | Reverse a string | Reverse a string `a_string` | def reversed_string(a_string):
return a_string[::(-1)] |
931,092 | Reverse a string | Reverse a string `s` | ''.join(reversed(s)) |
11,064,917 | Generate a sequence of numbers in Python | generate a string of numbers separated by comma which is divisible by `4` with remainder `1` or `2`. | """,""".join(str(i) for i in range(100) if i % 4 in (1, 2)) |
33,824,334 | How to convert this list into a dictionary | convert list `lst` of key, value pairs into a dictionary | dict([(e[0], int(e[1])) for e in lst]) |
10,213,994 | sorting a list of tuples in Python | sorting a list of tuples `list_of_tuples` where each tuple is reversed | sorted(list_of_tuples, key=lambda tup: tup[::-1]) |
10,213,994 | sorting a list of tuples in Python | sorting a list of tuples `list_of_tuples` by second key | sorted(list_of_tuples, key=lambda tup: tup[1]) |
9,236,926 | Concatenating two one-dimensional NumPy arrays | Concatenating two one-dimensional NumPy arrays 'a' and 'b'. | numpy.concatenate([a, b]) |
899,103 | Writing a list to a file with Python | writing items in list `thelist` to file `thefile` | for item in thelist:
thefile.write(('%s\n' % item)) |
899,103 | Writing a list to a file with Python | writing items in list `thelist` to file `thefile` | for item in thelist:
pass |
899,103 | Writing a list to a file with Python | serialize `itemlist` to file `outfile` | pickle.dump(itemlist, outfile) |
899,103 | Writing a list to a file with Python | writing items in list `itemlist` to file `outfile` | outfile.write('\n'.join(itemlist)) |
2,631,935 | SQLAlchemy: a better way for update with declarative? | Update a user's name as `Bob Marley` having id `123` in SQLAlchemy | session.query(User).filter_by(id=123).update({'name': 'Bob Marley'}) |
7,164,679 | How to send cookies in a post request with the Python Requests library? | 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) |
14,850,853 | How to include third party Python libraries in Google App Engine? | insert directory 'libs' at the 0th index of current directory | sys.path.insert(0, 'libs') |
415,511 | get current time | get current date and time | datetime.datetime.now() |
415,511 | get current time | get current time | datetime.datetime.now().time() |
415,511 | get current time | get current time in pretty format | strftime('%Y-%m-%d %H:%M:%S', gmtime()) |
415,511 | get current time | get current time in string format | str(datetime.now()) |
415,511 | get current time | get current time | datetime.datetime.time(datetime.datetime.now()) |
19,819,863 | Converting hex to int in python | convert hex '\xff' to integer | ord('\xff') |
37,497,559 | Python Pandas Identify Duplicated rows with Additional Column | identify duplicated rows in columns 'PplNum' and 'RoomNum' with additional column in dataframe `df` | df.groupby(['PplNum', 'RoomNum']).cumcount() + 1 |
15,940,280 | How to get UTC time in Python? | get current utc time | datetime.utcnow() |
12,845,112 | Python: Make last item of array become the first | move last item of array `a` to the first position | a[-1:] + a[:-1] |
35,414,625 | pandas: how to run a pivot with a multi-index? | Convert dataframe `df` to a pivot table using column 'year', 'month', and 'item' as indexes | df.set_index(['year', 'month', 'item']).unstack(level=-1) |
35,414,625 | pandas: how to run a pivot with a multi-index? | run a pivot with a multi-index `year` and `month` in a pandas data frame | df.pivot_table(values='value', index=['year', 'month'], columns='item') |
39,381,222 | How to print/show an expression in rational number form in python | print a rational number `3/2` | print('\n\x1b[4m' + '3' + '\x1b[0m' + '\n2') |
7,996,940 | What is the best way to sort list with custom sorting parameters in Python? | null | li1.sort(key=lambda x: not x.startswith('b.')) |
3,476,732 | How to loop backwards in python? | iterate backwards from 10 to 0 | range(10, 0, -1) |
317,413 | Get Element value with minidom with Python | get value of first child of xml node `name` | name[0].firstChild.nodeValue |
849,674 | Simple threading in Python 2.6 using thread.start_new_thread() | start a new thread for `myfunction` with parameters 'MyStringHere' and 1 | thread.start_new_thread(myfunction, ('MyStringHere', 1)) |
849,674 | Simple threading in Python 2.6 using thread.start_new_thread() | start a new thread for `myfunction` with parameters 'MyStringHere' and 1 | thread.start_new_thread(myfunction, ('MyStringHere', 1)) |
3,989,016 | How to find all positions of the maximum value in a list? | get index of the first biggest element in list `a` | a.index(max(a)) |
42,731,970 | Regex add character to matched string | replace periods `.` that are not followed by periods or spaces with a period and a space `. ` | re.sub('\\.(?=[^ .])', '. ', para) |
33,147,992 | how to turn a string of letters embedded in squared brackets into embedded lists | convert a string `a` of letters embedded in squared brackets into embedded lists | [i.split() for i in re.findall('\\[([^\\[\\]]+)\\]', a)] |
7,900,882 | extract item from list of dictionaries | 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'] |
7,900,882 | extract item from list of dictionaries | extract dictionary from list of dictionaries based on a key's value. | [d for d in a if d['name'] == 'pluto'] |
16,228,248 | Python: simplest way to get list of values from dict? | Retrieve list of values from dictionary 'd' | list(d.values()) |
943,809 | String manipulation in Cython | replace occurrences of two whitespaces or more with one whitespace ' ' in string `s` | re.sub(' +', ' ', s) |
14,104,778 | Set execute bit for a file using python | Change the mode of file 'my_script.sh' to permission number 484 | os.chmod('my_script.sh', 484) |
30,605,909 | Pandas to_csv call is prepending a comma | write pandas dataframe `df` to the file 'c:\\data\\t.csv' without row names | df.to_csv('c:\\data\\t.csv', index=False) |
18,082,130 | Python regex to remove all words which contains number | remove all words which contains number from a string `words` using regex | re.sub('\\w*\\d\\w*', '', words).strip() |
1,946,181 | How can I control the keyboard and mouse with Python? | control the keyboard and mouse with dogtail in linux | dogtail.rawinput.click(100, 100) |
1,101,508 | How to parse dates with -0400 timezone string in python? | parse date string '2009/05/13 19:19:30 -0400' using format '%Y/%m/%d %H:%M:%S %z' | datetime.strptime('2009/05/13 19:19:30 -0400', '%Y/%m/%d %H:%M:%S %z') |
2,674,391 | Python - Locating the position of a regex match in a string? | Get the position of a regex match for word `is` in a string `String` | re.search('\\bis\\b', String).start() |
2,674,391 | Python - Locating the position of a regex match in a string? | Get the position of a regex match `is` in a string `String` | re.search('is', String).start() |
2,233,917 | How to input an integer tuple from user? | input an integer tuple from user | tuple(map(int, input().split(','))) |
2,233,917 | How to input an integer tuple from user? | input a tuple of integers from user | tuple(int(x.strip()) for x in input().split(',')) |
13,093,727 | How to replace unicode characters in string with something else python? | replace unicode character '\u2022' in string 'str' with '*' | str.decode('utf-8').replace('\u2022', '*').encode('utf-8') |
13,093,727 | How to replace unicode characters in string with something else python? | replace unicode characters ''\u2022' in string 'str' with '*' | str.decode('utf-8').replace('\u2022', '*') |
18,200,052 | How to convert ndarray to array? | convert ndarray with shape 3x3 to array | np.zeros((3, 3)).ravel() |
1,854 | What OS am I running on | get os name | import platform
platform.system() |
1,854 | What OS am I running on | get os version | import platform
platform.release() |
1,854 | What OS am I running on | get the name of the OS | print(os.name) |
11,791,568 | What is the most pythonic way to exclude elements of a list that start with a specific character? | null | [x for x in my_list if not x.startswith('#')] |
2,847,272 | Python string formatting when string contains "%s" without escaping | replace fields delimited by braces {} in string "Day old bread, 50% sale {0}" with string 'today' | """Day old bread, 50% sale {0}""".format('today') |
15,148,684 | List of Tuples (string, float)with NaN How to get the min value? | Get a minimum value from a list of tuples `list` with values of type `string` and `float` with nan | min(list, key=lambda x: float('inf') if math.isnan(x[1]) else x[1]) |
2,153,444 | Python: Finding average of a nested list | Find average of a nested list `a` | a = [(sum(x) / len(x)) for x in zip(*a)] |
17,558,552 | How do I add custom field to Python log format string? | Log info message 'Log message' with attributes `{'app_name': 'myapp'}` | logging.info('Log message', extra={'app_name': 'myapp'}) |
21,771,133 | finding non-numeric rows in dataframe in pandas? | replace values of dataframe `df` with True if numeric | df.applymap(lambda x: isinstance(x, (int, float))) |
39,129,846 | Sort list of mixed strings based on digits | sort list `l` based on its elements' digits | sorted(l, key=lambda x: int(re.search('\\d+', x).group(0))) |
8,009,176 | Function to close the window in Tkinter | close the window in tkinter | self.root.destroy() |
36,454,494 | Calcuate mean for selected rows for selected columns in pandas data frame | get mean of columns `2, 5, 6, 7, 8` for all rows in dataframe `df` | df.iloc[:, ([2, 5, 6, 7, 8])].mean(axis=1) |
12,224,778 | How to filter by sub-level index in Pandas | filter dataframe `df` by sub-level index '0630' in pandas | df[df.index.map(lambda x: x[1].endswith('0630'))] |
4,921,038 | Deleting row with Flask-SQLAlchemy | flask-sqlalchemy delete row `page` | db.session.delete(page) |
2,783,079 | How do I convert a unicode to a string at the Python level? | Format a string `u'Andr\xc3\xa9'` that has unicode characters | """""".join(chr(ord(c)) for c in 'Andr\xc3\xa9') |
2,783,079 | How do I convert a unicode to a string at the Python level? | convert a unicode 'Andr\xc3\xa9' to a string | """""".join(chr(ord(c)) for c in 'Andr\xc3\xa9').decode('utf8') |
120,656 | Directory listing | list all files in directory "." | for (dirname, dirnames, filenames) in os.walk('.'):
for subdirname in dirnames:
print(os.path.join(dirname, subdirname))
for filename in filenames:
pass |
120,656 | Directory listing | list all files in directory `path` | os.listdir(path) |
11,816,315 | How to rename all folders? | rename file `dir` to `dir` + '!' | os.rename(dir, dir + '!') |
3,258,573 | Pythonic way to insert every 2 elements in a string | Insert a character `-` after every two elements in a string `s` | """-""".join(a + b for a, b in zip(s[::2], s[1::2])) |
3,241,594 | Printing numbers in python | printing numbers rounding up to third decimal place | print('%.3f' % 3.1415) |
22,296,496 | Add element to a json in python | add variable `var` to key 'f' of first element in JSON data `data` | data[0]['f'] = var |
247,770 | Retrieving python module path | get the path of module `a_module` | print(a_module.__file__) |
Subsets and Splits