question_id
int64 1.48k
42.8M
| intent
stringlengths 11
122
| rewritten_intent
stringlengths 4
183
⌀ | snippet
stringlengths 2
232
|
---|---|---|---|
12,005,558 | Python - find digits in a string | get digits in string `my_string` | """""".join(c for c in my_string if c.isdigit()) |
10,974,932 | python split string based on regular expression | split string `str1` on one or more spaces with a regular expression | re.split(' +', str1) |
10,974,932 | python split string based on regular expression | null | re.findall('\\S+', str1) |
14,925,239 | Python: How to get attribute of attribute of an object with getattr? | Evaluate a nested dictionary `myobject.id.number` to get `number` if `myobject` is present with getattr | getattr(getattr(myobject, 'id', None), 'number', None) |
17,815,945 | Convert generator object to a dictionary | convert generator object to a dictionary | {i: (i * 2) for i in range(10)} |
17,815,945 | Convert generator object to a dictionary | convert generator object to a dictionary | dict((i, i * 2) for i in range(10)) |
741,877 | How do I tell matplotlib that I am done with a plot? | Matplotlib clear the current axes. | plt.cla() |
21,212,706 | Python Convert String Literal to Float | split string `s` into float values and write sum to `total` | total = sum(float(item) for item in s.split(',')) |
4,523,551 | Python ASCII to binary | Convert ascii value 'P' to binary | bin(ord('P')) |
12,572,362 | Get a string after a specific substring | print a string after a specific substring ', ' in string `my_string ` | print(my_string.split(', ', 1)[1]) |
23,306,653 | Python Accessing Nested JSON Data | get value of key `post code` associated with first index of key `places` of dictionary `data` | print(data['places'][0]['post code']) |
33,724,111 | Python RegEx using re.sub with multiple patterns | remove colon character surrounded by vowels letters in string `word` | word = re.sub('([aeiou]):(([aeiou][^aeiou]*){3})$', '\\1\\2', word) |
6,407,780 | How to extract data from JSON Object in Python? | extract data field 'bar' from json object | json.loads('{"foo": 42, "bar": "baz"}')['bar'] |
10,973,614 | Convert JSON array to Python list | Convert JSON array `array` to Python object | data = json.loads(array) |
10,973,614 | Convert JSON array to Python list | Convert JSON array `array` to Python object | data = json.loads(array) |
2,527,892 | Parsing a tweet to extract hashtags into an array in Python | pars a string 'http://example.org/#comments' to extract hashtags into an array | re.findall('#(\\w+)', 'http://example.org/#comments') |
14,411,633 | Python - Fastest way to check if a string contains specific characters in any of the items in a list | do a boolean check if a string `lestring` contains any of the items in list `lelist` | any(e in lestring for e in lelist) |
17,812,978 | How to plot two columns of a pandas data frame using points? | null | df.plot(x='col_name_1', y='col_name_2', style='o') |
11,709,079 | Parsing HTML | Parsing HTML string `html` using BeautifulSoup | parsed_html = BeautifulSoup(html)
print(parsed_html.body.find('div', attrs={'class': 'container', }).text) |
11,709,079 | Parsing HTML | Parsing webpage 'http://www.google.com/' using BeautifulSoup | page = urllib.request.urlopen('http://www.google.com/')
soup = BeautifulSoup(page) |
17,109,608 | change figure size and figure format in matplotlib | change figure size to 3 by 4 in matplotlib | plt.figure(figsize=(3, 4)) |
265,960 | Best way to strip punctuation from a string in Python | Strip punctuation from string `s` | s.translate(None, string.punctuation) |
2,229,827 | Django urlsafe base64 decoding with decryption | django urlsafe base64 decode string `uenc` with decryption | base64.urlsafe_b64decode(uenc.encode('ascii')) |
35,427,814 | Get the number of all keys in a dictionary of dictionaries in Python | get the number of all keys in the nested dictionary `dict_list` | len(dict_test) + sum(len(v) for v in dict_test.values()) |
5,796,238 | Python convert decimal to hex | return the conversion of decimal `d` to hex without the '0x' prefix | hex(d).split('x')[1] |
13,905,936 | converting integer to list in python | create a list containing digits of number 123 as its elements | list(str(123)) |
13,905,936 | converting integer to list in python | converting integer `num` to list | [int(x) for x in str(num)] |
2,582,580 | Python Mechanize select a form with no name | select a first form with no name in mechanize | br.select_form(nr=0) |
13,156,395 | Python load json file with UTF-8 BOM header | Open file 'sample.json' in read mode with encoding of 'utf-8-sig' | json.load(codecs.open('sample.json', 'r', 'utf-8-sig')) |
13,156,395 | Python load json file with UTF-8 BOM header | load json file 'sample.json' with utf-8 bom header | json.loads(open('sample.json').read().decode('utf-8-sig')) |
12,030,179 | Issue sending email with python? | setup a smtp mail server to `smtp.gmail.com` with port `587` | server = smtplib.SMTP('smtp.gmail.com', 587) |
12,681,945 | Reversing bits of Python integer | revers correlating bits of integer `n` | int('{:08b}'.format(n)[::-1], 2) |
11,040,626 | Pandas DataFrame Add column to index without resetting | add column `d` to index of dataframe `df` | df.set_index(['d'], append=True) |
3,294,889 | Iterating over dictionaries using for loops | Iterating over a dictionary `d` using for loops | for (key, value) in d.items():
pass |
3,294,889 | Iterating over dictionaries using for loops | Iterating over a dictionary `d` using for loops | for (key, value) in list(d.items()):
pass |
3,294,889 | Iterating over dictionaries using for loops | Iterating key and items over dictionary `d` | for (letter, number) in list(d.items()):
pass |
3,294,889 | Iterating over dictionaries using for loops | Iterating key and items over dictionary `d` | for (k, v) in list(d.items()):
pass |
3,294,889 | Iterating over dictionaries using for loops | get keys and items of dictionary `d` | list(d.items()) |
3,294,889 | Iterating over dictionaries using for loops | get keys and items of dictionary `d` as a list | list(d.items()) |
3,294,889 | Iterating over dictionaries using for loops | Iterating key and items over dictionary `d` | for (k, v) in list(d.items()):
pass |
3,294,889 | Iterating over dictionaries using for loops | Iterating key and items over dictionary `d` | for (letter, number) in list(d.items()):
pass |
3,294,889 | Iterating over dictionaries using for loops | Iterating key and items over dictionary `d` | for (letter, number) in list(d.items()):
pass |
18,102,109 | How do I implement a null coalescing operator in SQLAlchemy? | query all data from table `Task` where the value of column `time_spent` is bigger than 3 hours | session.query(Task).filter(Task.time_spent > timedelta(hours=3)).all() |
498,106 | How do I compile a Visual Studio project from the command-line? | compile Visual Studio project `project.sln` from the command line through python | os.system('msbuild project.sln /p:Configuration=Debug') |
3,108,042 | Get max key in dictionary | get max key in dictionary `MyCount` | max(list(MyCount.keys()), key=int) |
6,856,119 | Can I use an alias to execute a program from a python script | 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') |
251,464 | How to get a function name as a string in Python? | get a name of function `my_function` as a string | my_function.__name__ |
251,464 | How to get a function name as a string in Python? | null | my_function.__name__ |
14,859,458 | How to check if all values in the columns of a numpy matrix are the same? | check if all values in the columns of a numpy matrix `a` are same | np.all(a == a[(0), :], axis=0) |
40,384,599 | Sorting a list of tuples by the addition of second and third element of the tuple | sort list `a` in ascending order based on the addition of the second and third elements of each tuple in it | sorted(a, key=lambda x: (sum(x[1:3]), x[0])) |
40,384,599 | Sorting a list of tuples by the addition of second and third element of the tuple | sort a list of tuples `a` by the sum of second and third element of each tuple | sorted(a, key=lambda x: (sum(x[1:3]), x[0]), reverse=True) |
40,384,599 | Sorting a list of tuples by the addition of second and third element of the tuple | sorting a list of tuples `lst` by the sum of the second elements onwards, and third element of the tuple | sorted(lst, key=lambda x: (sum(x[1:]), x[0])) |
40,384,599 | Sorting a list of tuples by the addition of second and third element of the tuple | sort the list of tuples `lst` by the sum of every value except the first and by the first value in reverse order | sorted(lst, key=lambda x: (sum(x[1:]), x[0]), reverse=True) |
19,410,585 | Add headers in a Flask app with unicode_literals | add header 'WWWAuthenticate' in a flask app with value 'Basic realm="test"' | response.headers['WWW-Authenticate'] = 'Basic realm="test"' |
2,375,335 | In Django, how do I clear a sessionkey? | clear session key 'mykey' | del request.session['mykey'] |
2,803,852 | Python date string to date object | convert date string '24052010' to date object in format '%d%m%Y' | datetime.datetime.strptime('24052010', '%d%m%Y').date() |
20,078,816 | Replace non-ASCII characters with a single space | Replace non-ASCII characters in string `text` with a single space | re.sub('[^\\x00-\\x7F]+', ' ', text) |
10,346,336 | List of lists into numpy array | null | numpy.array([[1, 2], [3, 4]]) |
11,479,392 | What does a for loop within a list do in Python? | Get a list `myList` from 1 to 10 | myList = [i for i in range(10)] |
40,582,103 | using regular expression to split string in python | use regex pattern '((.+?)\\2+)' to split string '44442(2)2(2)44' | [m[0] for m in re.compile('((.+?)\\2+)').findall('44442(2)2(2)44')] |
40,582,103 | using regular expression to split string in python | use regular expression '((\\d)(?:[()]*\\2*[()]*)*)' to split string `s` | [i[0] for i in re.findall('((\\d)(?:[()]*\\2*[()]*)*)', s)] |
41,071,947 | How to remove the space between subplots in matplotlib.pyplot? | remove the space between subplots in matplotlib.pyplot | fig.subplots_adjust(wspace=0, hspace=0) |
10,201,977 | How to reverse tuples in Python? | Reverse list `x` | x[::-1] |
983,855 | Python JSON encoding | null | json.dumps({'apple': 'cat', 'banana': 'dog', 'pear': 'fish'}) |
6,916,542 | Writing List of Strings to Excel CSV File in Python | write a list of strings `row` to csv object `csvwriter` | csvwriter.writerow(row) |
794,995 | How to convert datetime to string in python in django | Jinja2 formate date `item.date` accorto pattern 'Y M d' | {{(item.date | date): 'Y M d'}} |
5,801,945 | Non-consuming regular expression split in Python | Split a string `text` with comma, question mark or exclamation by non-consuming regex using look-behind | re.split('(?<=[\\.\\?!]) ', text) |
372,102 | UTF in Python Regex | create a regular expression object with the pattern '\xe2\x80\x93' | re.compile('\xe2\x80\x93') |
1,514,553 | declare an array | declare an array `variable` | variable = [] |
1,514,553 | declare an array | declare an array with element 'i' | intarray = array('i') |
39,821,166 | How to reverse the elements in a sublist? | given list `to_reverse`, reverse the all sublists and the list itself | [sublist[::-1] for sublist in to_reverse[::-1]] |
12,985,456 | Replace all non-alphanumeric characters in a string | null | re.sub('[^0-9a-zA-Z]+', '*', 'h^&ell`.,|o w]{+orld') |
20,876,077 | Python: unescape special characters without splitting data | unescape special characters without splitting data in array of strings `['I ', u'<', '3s U ', u'&', ' you luvz me']` | """""".join(['I ', '<', '3s U ', '&', ' you luvz me']) |
5,255,657 | How can I disable logging while running unit tests in Python Django? | disable logging while running unit tests in python django | logging.disable(logging.CRITICAL) |
13,042,013 | Adding url to mysql row in python | adding url `url` to mysql row | cursor.execute('INSERT INTO index(url) VALUES(%s)', (url,)) |
19,738,169 | Convert column of date objects in Pandas DataFrame to strings | convert column of date objects 'DateObj' in pandas dataframe `df` to strings in new column 'DateStr' | df['DateStr'] = df['DateObj'].dt.strftime('%d%m%Y') |
15,210,485 | python regex get first part of an email address | split string `s` by '@' and get the first element | s.split('@')[0] |
41,513,324 | Python Pandas: drop rows of a timeserie based on time range | drop rows of dataframe `df` whose index is smaller than the value of `start_remove` or bigger than the value of`end_remove` | df.query('index < @start_remove or index > @end_remove') |
41,513,324 | Python Pandas: drop rows of a timeserie based on time range | Drop the rows in pandas timeseries `df` from the row containing index `start_remove` to the row containing index `end_remove` | df.loc[(df.index < start_remove) | (df.index > end_remove)] |
26,266,362 | How to count the Nan values in the column in Panda Data frame | Get the number of NaN values in each column of dataframe `df` | df.isnull().sum() |
20,110,170 | Turn Pandas Multi-Index into column | reset index of dataframe `df`so that existing index values are transferred into `df`as columns | df.reset_index(inplace=True) |
7,271,482 | python getting a list of value from list of dict | generate a list containing values associated with the key 'value' of each dictionary inside list `list_of_dicts` | [x['value'] for x in list_of_dicts] |
7,271,482 | python getting a list of value from list of dict | null | [d['value'] for d in l] |
7,271,482 | python getting a list of value from list of dict | null | [d['value'] for d in l if 'value' in d] |
1,966,207 | Converting NumPy array into Python List structure? | convert numpy array into python list structure | np.array([[1, 2, 3], [4, 5, 6]]).tolist() |
3,945,856 | Converting string to tuple and adding to tuple | converting string '(1,2,3,4)' to a tuple | ast.literal_eval('(1,2,3,4)') |
12,324,456 | How to keep a list of lists sorted as it is created | keep a list `dataList` of lists sorted as it is created by second element | dataList.sort(key=lambda x: x[1]) |
3,724,551 | Python: Uniqueness for list of lists | remove duplicated items from list of lists `testdata` | list(map(list, set(map(lambda i: tuple(i), testdata)))) |
3,724,551 | Python: Uniqueness for list of lists | uniqueness for list of lists `testdata` | [list(i) for i in set(tuple(i) for i in testdata)] |
4,789,021 | In Django, how do I check if a user is in a certain group? | in django, check if a user is in a group 'Member' | return user.groups.filter(name='Member').exists() |
4,789,021 | In Django, how do I check if a user is in a certain group? | check if a user `user` is in a group from list of groups `['group1', 'group2']` | return user.groups.filter(name__in=['group1', 'group2']).exists() |
19,617,355 | Dynamically changing log level in python without restarting the application | Change log level dynamically to 'DEBUG' without restarting the application | logging.getLogger().setLevel(logging.DEBUG) |
17,426,386 | How to transform a tuple to a string of values without comma and parentheses | Concat each values in a tuple `(34.2424, -64.2344, 76.3534, 45.2344)` to get a string | """""".join(str(i) for i in (34.2424, -64.2344, 76.3534, 45.2344)) |
4,605,439 | What is the simplest way to swap char in a string with Python? | swap each pair of characters in string `s` | """""".join([s[x:x + 2][::-1] for x in range(0, len(s), 2)]) |
9,402,255 | Drawing a huge graph with networkX and matplotlib | save current figure to file 'graph.png' with resolution of 1000 dpi | plt.savefig('graph.png', dpi=1000) |
41,313,232 | delete items from list of list: pythonic way | delete items from list `my_list` if the item exist in list `to_dell` | my_list = [[x for x in sublist if x not in to_del] for sublist in my_list] |
2,191,699 | Find an element in a list of tuples | find all the elements that consists value '1' in a list of tuples 'a' | [item for item in a if 1 in item] |
2,191,699 | Find an element in a list of tuples | find all elements in a list of tuples `a` where the first element of each tuple equals 1 | [item for item in a if item[0] == 1] |
18,816,297 | How can I get the index value of a list comprehension? | 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)} |
6,280,978 | how to uniqify a list of dict in python | null | [dict(y) for y in set(tuple(x.items()) for x in d)] |
Subsets and Splits