rewritten_intent
stringlengths 4
183
⌀ | intent
stringlengths 11
122
| snippet
stringlengths 2
232
| question_id
int64 1.48k
42.8M
|
---|---|---|---|
subprocess run command 'start command -flags arguments' through the shell | Python, running command line tools in parallel | subprocess.call('start command -flags arguments', shell=True) | 9,554,544 |
run command 'command -flags arguments &' on command line tools as separate processes | Python, running command line tools in parallel | subprocess.call('command -flags arguments &', shell=True) | 9,554,544 |
replace percent-encoded code in request `f` to their single-character equivalent | Passing the '+' character in a POST request in Python | f = urllib.request.urlopen(url, urllib.parse.unquote(urllib.parse.urlencode(params))) | 12,527,959 |
remove white spaces from the end of string " xyz " | How do I remove whitespace from the end of a string in Python? | """ xyz """.rstrip() | 2,372,573 |
Replace special characters in utf-8 encoded string `s` using the %xx escape | URL encoding in python | urllib.parse.quote(s.encode('utf-8')) | 8,905,864 |
null | URL encoding in python | urllib.parse.quote_plus('a b') | 8,905,864 |
Create an array containing the conversion of string '100110' into separate elements | Convert string to numpy array | np.array(map(int, '100110')) | 28,207,743 |
convert a string 'mystr' to numpy array of integer values | Convert string to numpy array | print(np.array(list(mystr), dtype=int)) | 28,207,743 |
convert an rgb image 'messi5.jpg' into grayscale `img` | How can I convert an RGB image into grayscale in Python? | img = cv2.imread('messi5.jpg', 0) | 12,201,577 |
sort list `lst` in descending order based on the second item of each tuple in it | sorting a graph by its edge weight. python | lst.sort(key=lambda x: x[2], reverse=True) | 11,584,773 |
null | How to find all occurrences of an element in a list? | indices = [i for i, x in enumerate(my_list) if x == 'whatever'] | 6,294,179 |
execute shell command 'grep -r PASSED *.log | sort -u | wc -l' with a | pipe in it | How can I execute shell command with a | pipe in it | subprocess.call('grep -r PASSED *.log | sort -u | wc -l', shell=True) | 18,050,937 |
count the number of trailing question marks in string `my_text` | How to count the number of a specific character at the end of a string ignoring duplicates? | len(my_text) - len(my_text.rstrip('?')) | 42,178,481 |
remove dollar sign '$' from second to last column data in dataframe 'df' and convert the data into floats | converting currency with $ to numbers in Python pandas | df[df.columns[1:]].replace('[\\$,]', '', regex=True).astype(float) | 32,464,280 |
Merge column 'word' in dataframe `df2` with column 'word' on dataframe `df1` | Conditionally fill a column of a pandas df with values of a different df | df1.merge(df2, how='left', on='word') | 42,060,144 |
switch positions of each two adjacent characters in string `a` | Switch every pair of characters in a string | print(''.join(''.join(i) for i in zip(a2, a1)) + a[-1] if len(a) % 2 else '') | 30,628,176 |
make a window `root` jump to the front | How to make a window jump to the front? | root.attributes('-topmost', True) | 1,892,339 |
make a window `root` jump to the front | How to make a window jump to the front? | root.lift() | 1,892,339 |
Convert list of booleans `walls` into a hex string | Elegant way to convert list to hex string | hex(int(''.join([str(int(b)) for b in walls]), 2)) | 17,731,822 |
convert the sum of list `walls` into a hex presentation | Elegant way to convert list to hex string | hex(sum(b << i for i, b in enumerate(reversed(walls)))) | 17,731,822 |
print the string `Total score for`, the value of the variable `name`, the string `is` and the value of the variable `score` in one print call. | Print multiple arguments in python | print(('Total score for', name, 'is', score)) | 15,286,401 |
print multiple arguments 'name' and 'score'. | Print multiple arguments in python | print('Total score for {} is {}'.format(name, score)) | 15,286,401 |
print a string using multiple strings `name` and `score` | Print multiple arguments in python | print('Total score for %s is %s ' % (name, score)) | 15,286,401 |
print string including multiple variables `name` and `score` | Print multiple arguments in python | print(('Total score for', name, 'is', score)) | 15,286,401 |
serve a static html page 'your_template.html' at the root of a django project | Is it possible to serve a static html page at the root of a django project? | url('^$', TemplateView.as_view(template_name='your_template.html')) | 30,650,254 |
use a list of values `[3,6]` to select rows from a pandas dataframe `df`'s column 'A' | use a list of values to select rows from a pandas dataframe | df[df['A'].isin([3, 6])] | 12,096,252 |
null | How to get the concrete class name as a string? | instance.__class__.__name__ | 521,502 |
execute python code `myscript.py` in a virtualenv `/path/to/my/venv` from matlab | How can I execute Python code in a virtualenv from Matlab | system('/path/to/my/venv/bin/python myscript.py') | 39,538,010 |
django return a QuerySet list containing the values of field 'eng_name' in model `Employees` | django models selecting single field | Employees.objects.values_list('eng_name', flat=True) | 7,503,241 |
find all digits in string '6,7)' and put them to a list | Python regex findall alternation behavior | re.findall('\\d|\\d,\\d\\)', '6,7)') | 31,465,002 |
prompt string 'Press Enter to continue...' to the console | How do I make python to wait for a pressed key | input('Press Enter to continue...') | 983,354 |
print string "ABC" as hex literal | Print string as hex literal python | """ABC""".encode('hex') | 21,947,035 |
insert a new field 'geolocCountry' on an existing document 'b' using pymongo | python + pymongo: how to insert a new field on an existing document in mongo from a for loop | db.Doc.update({'_id': b['_id']}, {'$set': {'geolocCountry': myGeolocCountry}}) | 15,666,169 |
Write a regex statement to match 'lol' to 'lolllll'. | Regex to match 'lol' to 'lolllll' and 'omg' to 'omggg', etc | re.sub('l+', 'l', 'lollll') | 3,895,874 |
BeautifulSoup find all 'tr' elements in HTML string `soup` at the five stride starting from the fourth element | Getting the nth element using BeautifulSoup | rows = soup.findAll('tr')[4::5] | 8,724,352 |
reverse all x-axis points in pyplot | Reverse Y-Axis in PyPlot | plt.gca().invert_xaxis() | 2,051,744 |
reverse y-axis in pyplot | Reverse Y-Axis in PyPlot | plt.gca().invert_yaxis() | 2,051,744 |
stack two dataframes next to each other in pandas | How do I stack two DataFrames next to each other in Pandas? | pd.concat([GOOG, AAPL], keys=['GOOG', 'AAPL'], axis=1) | 13,079,852 |
create a json response `response_data` | Creating a JSON response using Django and Python | return HttpResponse(json.dumps(response_data), content_type='application/json') | 2,428,092 |
decode escape sequences in string `myString` | Process escape sequences in a string | myString.decode('string_escape') | 4,020,539 |
calculate the md5 checksum of a file named 'filename.exe' | How do I calculate the md5 checksum of a file in Python? | hashlib.md5(open('filename.exe', 'rb').read()).hexdigest() | 16,874,598 |
Find all keys from a dictionary `d` whose values are `desired_value` | Finding key from value in Python dictionary: | [k for k, v in d.items() if v == desired_value] | 7,657,457 |
create a set containing all keys' names from dictionary `LoD` | Extract all keys from a list of dictionaries | {k for d in LoD for k in list(d.keys())} | 11,399,384 |
create a set containing all keys names from list of dictionaries `LoD` | Extract all keys from a list of dictionaries | set([i for s in [list(d.keys()) for d in LoD] for i in s]) | 11,399,384 |
extract all keys from a list of dictionaries `LoD` | Extract all keys from a list of dictionaries | [i for s in [list(d.keys()) for d in LoD] for i in s] | 11,399,384 |
unpack keys and values of a dictionary `d` into two lists | Is there a more elegant way for unpacking keys and values of a dictionary into two lists, without losing consistence? | keys, values = zip(*list(d.items())) | 6,612,769 |
convert a string `s` containing a decimal to an integer | Convert a string to integer with decimal in Python | int(Decimal(s)) | 1,094,717 |
null | Convert a string to integer with decimal in Python | int(s.split('.')[0]) | 1,094,717 |
check if array `b` contains all elements of array `a` | Numpy: How to check if array contains certain numbers? | numpy.in1d(b, a).all() | 10,565,598 |
numpy: check if array 'a' contains all the numbers in array 'b'. | Numpy: How to check if array contains certain numbers? | numpy.array([(x in a) for x in b]) | 10,565,598 |
Draw node labels `labels` on networkx graph `G ` at position `pos` | Node labels using networkx | networkx.draw_networkx_labels(G, pos, labels) | 15,548,506 |
make a row-by-row copy `y` of array `x` | How to make a copy of a 2D array in Python? | y = [row[:] for row in x] | 6,532,881 |
Create 2D numpy array from the data provided in 'somefile.csv' with each row in the file having same number of values | Pythonic way to populate numpy array | X = numpy.loadtxt('somefile.csv', delimiter=',') | 7,356,042 |
get a list of items from the list `some_list` that contain string 'abc' | Check if a Python list item contains a string inside another string | matching = [s for s in some_list if 'abc' in s] | 4,843,158 |
export a pandas data frame `df` to a file `mydf.tsv` and retain the indices | How to write/read a Pandas DataFrame with MultiIndex from/to an ASCII file? | df.to_csv('mydf.tsv', sep='\t') | 11,041,411 |
null | How do I create a LIST of unique random numbers? | random.sample(list(range(100)), 10) | 9,755,538 |
split a string `s` on last delimiter | Splitting on last delimiter in Python string? | s.rsplit(',', 1) | 15,012,228 |
Check if all elements in list `lst` are tupples of long and int | Python check if all elements of a list are the same type | all(isinstance(x, int) for x in lst) | 13,252,333 |
check if all elements in a list 'lst' are the same type 'int' | Python check if all elements of a list are the same type | all(isinstance(x, int) for x in lst) | 13,252,333 |
strip a string `line` of all carriage returns and newlines | Python . How to get rid of '\r' in string? | line.strip() | 13,656,519 |
scroll to the bottom of a web page using selenium webdriver | How can I scroll a web page using selenium webdriver in python? | driver.execute_script('window.scrollTo(0, Y)') | 20,986,631 |
scroll a to the bottom of a web page using selenium webdriver | How can I scroll a web page using selenium webdriver in python? | driver.execute_script('window.scrollTo(0, document.body.scrollHeight);') | 20,986,631 |
convert Date object `dateobject` into a DateTime object | How do I convert a datetime.date object into datetime.datetime in python? | datetime.datetime.combine(dateobject, datetime.time()) | 11,619,169 |
check if any item from list `b` is in list `a` | How to check if one of the following items is in a list? | print(any(x in a for x in b)) | 740,287 |
save a numpy array `image_array` as an image 'outfile.jpg' | Saving a Numpy array as an image | scipy.misc.imsave('outfile.jpg', image_array) | 902,761 |
Remove anything in parenthesis from string `item` with a regex | Regex for removing data in parenthesis | item = re.sub(' ?\\([^)]+\\)', '', item) | 19,794,051 |
Remove word characters in parenthesis from string `item` with a regex | Regex for removing data in parenthesis | item = re.sub(' ?\\(\\w+\\)', '', item) | 19,794,051 |
Remove all data inside parenthesis in string `item` | Regex for removing data in parenthesis | item = re.sub(' \\(\\w+\\)', '', item) | 19,794,051 |
check if any elements in one list `list1` are in another list `list2` | Checking if any elements in one list are in another | len(set(list1).intersection(list2)) > 0 | 16,138,015 |
convert hex string `s` to decimal | convert hex to decimal | i = int(s, 16) | 9,210,525 |
convert hex string "0xff" to decimal | convert hex to decimal | int('0xff', 16) | 9,210,525 |
convert hex string "FFFF" to decimal | convert hex to decimal | int('FFFF', 16) | 9,210,525 |
convert hex string '0xdeadbeef' to decimal | convert hex to decimal | ast.literal_eval('0xdeadbeef') | 9,210,525 |
convert hex string 'deadbeef' to decimal | convert hex to decimal | int('deadbeef', 16) | 9,210,525 |
take screenshot 'screen.png' on mac os x | Take screenshot in Python on Mac OS X | os.system('screencapture screen.png') | 4,524,723 |
Set a window size to `1400, 1000` using selenium webdriver | How to set window size using phantomjs and selenium webdriver in python | driver.set_window_size(1400, 1000) | 21,899,953 |
replace non-ascii chars from a unicode string u'm\xfasica' | Replace non-ascii chars from a unicode string in Python | unicodedata.normalize('NFKD', 'm\xfasica').encode('ascii', 'ignore') | 3,704,731 |
concatenate dataframe `df1` with `df2` whilst removing duplicates | Pandas/Python: How to concatenate two dataframes without duplicates? | pandas.concat([df1, df2]).drop_duplicates().reset_index(drop=True) | 21,317,384 |
Construct an array with data type float32 `a` from data in binary file 'filename' | numpy: efficiently reading a large array | a = numpy.fromfile('filename', dtype=numpy.float32) | 4,365,964 |
execute a mv command `mv /home/somedir/subdir/* somedir/` in subprocess | How to use the mv command in Python with subprocess | subprocess.call('mv /home/somedir/subdir/* somedir/', shell=True) | 21,804,935 |
null | How to use the mv command in Python with subprocess | subprocess.call('mv /home/somedir/subdir/* somedir/', shell=True) | 21,804,935 |
print a character that has unicode value `\u25b2` | How to use Unicode characters in a python string | print('\u25b2'.encode('utf-8')) | 16,658,068 |
compare contents at filehandles `file1` and `file2` using difflib | Comparing two .txt files using difflib in Python | difflib.SequenceMatcher(None, file1.read(), file2.read()) | 977,491 |
Create a dictionary from string `e` separated by `-` and `,` | Creating a dictionary from a string | dict((k, int(v)) for k, v in (e.split(' - ') for e in s.split(','))) | 4,627,981 |
check if all elements in a tuple `(1, 6)` are in another `(1, 2, 3, 4, 5)` | How to check if all elements in a tuple or list are in another? | all(i in (1, 2, 3, 4, 5) for i in (1, 6)) | 34,468,983 |
extract unique dates from time series 'Date' in dataframe `df` | python pandas extract unique dates from time series | df['Date'].map(lambda t: t.date()).unique() | 14,673,394 |
right align string `mystring` with a width of 7 | Formatting text to be justified in Python 3.3 with .format() method | """{:>7s}""".format(mystring) | 16,159,228 |
read an excel file 'ComponentReport-DJI.xls' | How do I read an Excel file into Python using xlrd? Can it read newer Office formats? | open('ComponentReport-DJI.xls', 'rb').read(200) | 118,516 |
sort dataframe `df` based on column 'b' in ascending and column 'c' in descending | How to sort a dataFrame in python pandas by two or more columns? | df.sort_values(['b', 'c'], ascending=[True, False], inplace=True) | 17,141,558 |
sort dataframe `df` based on column 'a' in ascending and column 'b' in descending | How to sort a dataFrame in python pandas by two or more columns? | df.sort_values(['a', 'b'], ascending=[True, False]) | 17,141,558 |
sort a pandas data frame with column `a` in ascending and `b` in descending order | How to sort a dataFrame in python pandas by two or more columns? | df1.sort(['a', 'b'], ascending=[True, False], inplace=True) | 17,141,558 |
sort a pandas data frame by column `a` in ascending, and by column `b` in descending order | How to sort a dataFrame in python pandas by two or more columns? | df.sort(['a', 'b'], ascending=[True, False]) | 17,141,558 |
django redirect to view 'Home.views.index' | Django redirect to root from a view | redirect('Home.views.index') | 7,284,952 |
remove all values within one list `[2, 3, 7]` from another list `a` | Remove all values within one list from another list in python | [x for x in a if x not in [2, 3, 7]] | 2,514,961 |
remove the punctuation '!', '.', ':' from a string `asking` | How to remove all the punctuation in a string? (Python) | out = ''.join(c for c in asking if c not in ('!', '.', ':')) | 16,050,952 |
BeautifulSoup get value associated with attribute 'content' where attribute 'name' is equal to 'City' in tag 'meta' in HTML parsed string `soup` | Python: BeautifulSoup - get an attribute value based on the name attribute | soup.find('meta', {'name': 'City'})['content'] | 11,205,386 |
unquote a urlencoded unicode string '%0a' | How to unquote a urlencoded unicode string in python? | urllib.parse.unquote('%0a') | 300,445 |
decode url `url` from UTF-16 code to UTF-8 code | How to unquote a urlencoded unicode string in python? | urllib.parse.unquote(url).decode('utf8') | 300,445 |
empty a list `lst` | empty a list | del lst[:] | 1,400,608 |
empty a list `lst` | empty a list | del lst1[:] | 1,400,608 |