idx
int64 0
2.38k
| question
stringlengths 5
184
| target
stringlengths 5
213
|
|---|---|---|
200
|
subprocess run command 'start command -flags arguments' through the shell
|
subprocess . call ( 'start command -flags arguments' , shell = True )
|
201
|
run command 'command -flags arguments &' on command line tools as separate processes
|
subprocess . call ( 'command -flags arguments &' , shell = True )
|
202
|
replace percent-encoded code in request `f` to their single-character equivalent
|
f = urllib . request . urlopen ( url , urllib . parse . unquote ( urllib . parse . urlencode ( params ) ) )
|
203
|
remove white spaces from the end of string " xyz "
|
""" xyz """ . rstrip ( )
|
204
|
Replace special characters in utf-8 encoded string `s` using the %xx escape
|
urllib . parse . quote ( s . encode ( 'utf-8' ) )
|
205
|
URL encoding in python
|
urllib . parse . quote_plus ( 'a b' )
|
206
|
Create an array containing the conversion of string '100110' into separate elements
|
np . array ( map ( int , '100110' ) )
|
207
|
convert a string 'mystr' to numpy array of integer values
|
print ( np . array ( list ( mystr ) , dtype = int ) )
|
208
|
convert an rgb image 'messi5.jpg' into grayscale `img`
|
img = cv2 . imread ( 'messi5.jpg' , 0 )
|
209
|
sort list `lst` in descending order based on the second item of each tuple in it
|
lst . sort ( key = lambda x : x [ 2 ] , reverse = True )
|
210
|
How to find all occurrences of an element in a list?
|
indices = [ i for i , x in enumerate ( my_list ) if x == 'whatever' ]
|
211
|
execute shell command 'grep -r PASSED *.log | sort -u | wc -l' with a | pipe in it
|
subprocess . call ( 'grep -r PASSED *.log | sort -u | wc -l' , shell = True )
|
212
|
count the number of trailing question marks in string `my_text`
|
len ( my_text ) - len ( my_text . rstrip ( '?' ) )
|
213
|
remove dollar sign '$' from second to last column data in dataframe 'df' and convert the data into floats
|
df [ df . columns [ 1 : ] ] . replace ( '[\\$,]' , '' , regex = True ) . astype ( float )
|
214
|
Merge column 'word' in dataframe `df2` with column 'word' on dataframe `df1`
|
df1 . merge ( df2 , how = 'left' , on = 'word' )
|
215
|
switch positions of each two adjacent characters in string `a`
|
print ( '' . join ( '' . join ( i ) for i in zip ( a2 , a1 ) ) + a [ - 1 ] if len ( a ) % 2 else '' )
|
216
|
make a window `root` jump to the front
|
root . attributes ( '-topmost' , True )
|
217
|
make a window `root` jump to the front
|
root . lift ( )
|
218
|
Convert list of booleans `walls` into a hex string
|
hex ( int ( '' . join ( [ str ( int ( b ) ) for b in walls ] ) , 2 ) )
|
219
|
convert the sum of list `walls` into a hex presentation
|
hex ( sum ( b << i for i , b in enumerate ( reversed ( walls ) ) ) )
|
220
|
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 ( ( 'Total score for' , name , 'is' , score ) )
|
221
|
print multiple arguments 'name' and 'score'.
|
print ( 'Total score for {} is {}' . format ( name , score ) )
|
222
|
print a string using multiple strings `name` and `score`
|
print ( 'Total score for %s is %s ' % ( name , score ) )
|
223
|
print string including multiple variables `name` and `score`
|
print ( ( 'Total score for' , name , 'is' , score ) )
|
224
|
serve a static html page 'your_template.html' at the root of a django project
|
url ( '^$' , TemplateView . as_view ( template_name = 'your_template.html' ) )
|
225
|
use a list of values `[3,6]` to select rows from a pandas dataframe `df`'s column 'A'
|
df [ df [ 'A' ] . isin ( [ 3 , 6 ] ) ]
|
226
|
How to get the concrete class name as a string?
|
instance . __class__ . __name__
|
227
|
execute python code `myscript.py` in a virtualenv `/path/to/my/venv` from matlab
|
system ( '/path/to/my/venv/bin/python myscript.py' )
|
228
|
django return a QuerySet list containing the values of field 'eng_name' in model `Employees`
|
Employees . objects . values_list ( 'eng_name' , flat = True )
|
229
|
find all digits in string '6,7)' and put them to a list
|
re . findall ( '\\d|\\d,\\d\\)' , '6,7)' )
|
230
|
prompt string 'Press Enter to continue...' to the console
|
input ( 'Press Enter to continue...' )
|
231
|
print string "ABC" as hex literal
|
"""ABC""" . encode ( 'hex' )
|
232
|
insert a new field 'geolocCountry' on an existing document 'b' using pymongo
|
db . Doc . update ( { '_id' : b [ '_id' ] } , { '$set' : { 'geolocCountry' : myGeolocCountry } } )
|
233
|
Write a regex statement to match 'lol' to 'lolllll'.
|
re . sub ( 'l+' , 'l' , 'lollll' )
|
234
|
BeautifulSoup find all 'tr' elements in HTML string `soup` at the five stride starting from the fourth element
|
rows = soup . findAll ( 'tr' ) [ 4 : : 5 ]
|
235
|
reverse all x-axis points in pyplot
|
plt . gca ( ) . invert_xaxis ( )
|
236
|
reverse y-axis in pyplot
|
plt . gca ( ) . invert_yaxis ( )
|
237
|
stack two dataframes next to each other in pandas
|
pd . concat ( [ GOOG , AAPL ] , keys = [ 'GOOG' , 'AAPL' ] , axis = 1 )
|
238
|
create a json response `response_data`
|
return HttpResponse ( json . dumps ( response_data ) , content_type = 'application/json' )
|
239
|
decode escape sequences in string `myString`
|
myString . decode ( 'string_escape' )
|
240
|
calculate the md5 checksum of a file named 'filename.exe'
|
hashlib . md5 ( open ( 'filename.exe' , 'rb' ) . read ( ) ) . hexdigest ( )
|
241
|
Find all keys from a dictionary `d` whose values are `desired_value`
|
[ k for k , v in d . items ( ) if v == desired_value ]
|
242
|
create a set containing all keys' names from dictionary `LoD`
|
{ k for d in LoD for k in list ( d . keys ( ) ) }
|
243
|
create a set containing all keys names from list of dictionaries `LoD`
|
set ( [ i for s in [ list ( d . keys ( ) ) for d in LoD ] for i in s ] )
|
244
|
extract all keys from a list of dictionaries `LoD`
|
[ i for s in [ list ( d . keys ( ) ) for d in LoD ] for i in s ]
|
245
|
unpack keys and values of a dictionary `d` into two lists
|
keys , values = zip ( * list ( d . items ( ) ) )
|
246
|
convert a string `s` containing a decimal to an integer
|
int ( Decimal ( s ) )
|
247
|
Convert a string to integer with decimal in Python
|
int ( s . split ( '.' ) [ 0 ] )
|
248
|
check if array `b` contains all elements of array `a`
|
numpy . in1d ( b , a ) . all ( )
|
249
|
numpy: check if array 'a' contains all the numbers in array 'b'.
|
numpy . array ( [ ( x in a ) for x in b ] )
|
250
|
Draw node labels `labels` on networkx graph `G ` at position `pos`
|
networkx . draw_networkx_labels ( G , pos , labels )
|
251
|
make a row-by-row copy `y` of array `x`
|
y = [ row [ : ] for row in x ]
|
252
|
Create 2D numpy array from the data provided in 'somefile.csv' with each row in the file having same number of values
|
X = numpy . loadtxt ( 'somefile.csv' , delimiter = ',' )
|
253
|
get a list of items from the list `some_list` that contain string 'abc'
|
matching = [ s for s in some_list if 'abc' in s ]
|
254
|
export a pandas data frame `df` to a file `mydf.tsv` and retain the indices
|
df . to_csv ( 'mydf.tsv' , sep = '\t' )
|
255
|
How do I create a LIST of unique random numbers?
|
random . sample ( list ( range ( 100 ) ) , 10 )
|
256
|
split a string `s` on last delimiter
|
s . rsplit ( ',' , 1 )
|
257
|
Check if all elements in list `lst` are tupples of long and int
|
all ( isinstance ( x , int ) for x in lst )
|
258
|
check if all elements in a list 'lst' are the same type 'int'
|
all ( isinstance ( x , int ) for x in lst )
|
259
|
strip a string `line` of all carriage returns and newlines
|
line . strip ( )
|
260
|
scroll to the bottom of a web page using selenium webdriver
|
driver . execute_script ( 'window.scrollTo(0, Y)' )
|
261
|
scroll a to the bottom of a web page using selenium webdriver
|
driver . execute_script ( 'window.scrollTo(0, document.body.scrollHeight);' )
|
262
|
convert Date object `dateobject` into a DateTime object
|
datetime . datetime . combine ( dateobject , datetime . time ( ) )
|
263
|
check if any item from list `b` is in list `a`
|
print ( any ( x in a for x in b ) )
|
264
|
save a numpy array `image_array` as an image 'outfile.jpg'
|
scipy . misc . imsave ( 'outfile.jpg' , image_array )
|
265
|
Remove anything in parenthesis from string `item` with a regex
|
item = re . sub ( ' ?\\([^)]+\\)' , '' , item )
|
266
|
Remove word characters in parenthesis from string `item` with a regex
|
item = re . sub ( ' ?\\(\\w+\\)' , '' , item )
|
267
|
Remove all data inside parenthesis in string `item`
|
item = re . sub ( ' \\(\\w+\\)' , '' , item )
|
268
|
check if any elements in one list `list1` are in another list `list2`
|
len ( set ( list1 ) . intersection ( list2 ) ) > 0
|
269
|
convert hex string `s` to decimal
|
i = int ( s , 16 )
|
270
|
convert hex string "0xff" to decimal
|
int ( '0xff' , 16 )
|
271
|
convert hex string "FFFF" to decimal
|
int ( 'FFFF' , 16 )
|
272
|
convert hex string '0xdeadbeef' to decimal
|
ast . literal_eval ( '0xdeadbeef' )
|
273
|
convert hex string 'deadbeef' to decimal
|
int ( 'deadbeef' , 16 )
|
274
|
take screenshot 'screen.png' on mac os x
|
os . system ( 'screencapture screen.png' )
|
275
|
Set a window size to `1400, 1000` using selenium webdriver
|
driver . set_window_size ( 1400 , 1000 )
|
276
|
replace non-ascii chars from a unicode string u'm\xfasica'
|
unicodedata . normalize ( 'NFKD' , 'm\xfasica' ) . encode ( 'ascii' , 'ignore' )
|
277
|
concatenate dataframe `df1` with `df2` whilst removing duplicates
|
pandas . concat ( [ df1 , df2 ] ) . drop_duplicates ( ) . reset_index ( drop = True )
|
278
|
Construct an array with data type float32 `a` from data in binary file 'filename'
|
a = numpy . fromfile ( 'filename' , dtype = numpy . float32 )
|
279
|
execute a mv command `mv /home/somedir/subdir/* somedir/` in subprocess
|
subprocess . call ( 'mv /home/somedir/subdir/* somedir/' , shell = True )
|
280
|
How to use the mv command in Python with subprocess
|
subprocess . call ( 'mv /home/somedir/subdir/* somedir/' , shell = True )
|
281
|
print a character that has unicode value `\u25b2`
|
print ( '\u25b2' . encode ( 'utf-8' ) )
|
282
|
compare contents at filehandles `file1` and `file2` using difflib
|
difflib . SequenceMatcher ( None , file1 . read ( ) , file2 . read ( ) )
|
283
|
Create a dictionary from string `e` separated by `-` and `,`
|
dict ( ( k , int ( v ) ) for k , v in ( e . split ( ' - ' ) for e in s . split ( ',' ) ) )
|
284
|
check if all elements in a tuple `(1, 6)` are in another `(1, 2, 3, 4, 5)`
|
all ( i in ( 1 , 2 , 3 , 4 , 5 ) for i in ( 1 , 6 ) )
|
285
|
extract unique dates from time series 'Date' in dataframe `df`
|
df [ 'Date' ] . map ( lambda t : t . date ( ) ) . unique ( )
|
286
|
right align string `mystring` with a width of 7
|
"""{:>7s}""" . format ( mystring )
|
287
|
read an excel file 'ComponentReport-DJI.xls'
|
open ( 'ComponentReport-DJI.xls' , 'rb' ) . read ( 200 )
|
288
|
sort dataframe `df` based on column 'b' in ascending and column 'c' in descending
|
df . sort_values ( [ 'b' , 'c' ] , ascending = [ True , False ] , inplace = True )
|
289
|
sort dataframe `df` based on column 'a' in ascending and column 'b' in descending
|
df . sort_values ( [ 'a' , 'b' ] , ascending = [ True , False ] )
|
290
|
sort a pandas data frame with column `a` in ascending and `b` in descending order
|
df1 . sort ( [ 'a' , 'b' ] , ascending = [ True , False ] , inplace = True )
|
291
|
sort a pandas data frame by column `a` in ascending, and by column `b` in descending order
|
df . sort ( [ 'a' , 'b' ] , ascending = [ True , False ] )
|
292
|
django redirect to view 'Home.views.index'
|
redirect ( 'Home.views.index' )
|
293
|
remove all values within one list `[2, 3, 7]` from another list `a`
|
[ x for x in a if x not in [ 2 , 3 , 7 ] ]
|
294
|
remove the punctuation '!', '.', ':' from a string `asking`
|
out = '' . join ( c for c in asking if c not in ( '!' , '.' , ':' ) )
|
295
|
BeautifulSoup get value associated with attribute 'content' where attribute 'name' is equal to 'City' in tag 'meta' in HTML parsed string `soup`
|
soup . find ( 'meta' , { 'name' : 'City' } ) [ 'content' ]
|
296
|
unquote a urlencoded unicode string '%0a'
|
urllib . parse . unquote ( '%0a' )
|
297
|
decode url `url` from UTF-16 code to UTF-8 code
|
urllib . parse . unquote ( url ) . decode ( 'utf8' )
|
298
|
empty a list `lst`
|
del lst [ : ]
|
299
|
empty a list `lst`
|
del lst1 [ : ]
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.