idx
int64 0
2.38k
| question
stringlengths 5
184
| target
stringlengths 5
213
|
---|---|---|
500 | convert `a` to string
| str ( a )
|
501 | sort list of lists `L` by the second item in each list
| L . sort ( key = operator . itemgetter ( 1 ) )
|
502 | Print variable `count` and variable `conv` with space string ' ' in between
| print ( str ( count ) + ' ' + str ( conv ) )
|
503 | change NaN values in dataframe `df` using preceding values in the frame
| df . fillna ( method = 'ffill' , inplace = True )
|
504 | change the state of the Tkinter `Text` widget to read only i.e. `disabled`
| text . config ( state = DISABLED )
|
505 | python sum of ascii values of all characters in a string `string`
| sum ( map ( ord , string ) )
|
506 | apply itertools.product to elements of a list of lists `arrays`
| list ( itertools . product ( * arrays ) )
|
507 | print number `value` as thousands separators
| '{:,}' . format ( value )
|
508 | print number 1255000 as thousands separators
| locale . setlocale ( locale . LC_ALL , 'en_US' ) locale . format ( '%d' , 1255000 , grouping = True )
|
509 | get rows of dataframe `df` where column `Col1` has values `['men', 'rocks', 'mountains']`
| df [ df . Col1 . isin ( [ 'men' , 'rocks' , 'mountains' ] ) ]
|
510 | get the value at index 1 for each tuple in the list of tuples `L`
| [ x [ 1 ] for x in L ]
|
511 | split unicode string "раз два три" into words
| '\u0440\u0430\u0437 \u0434\u0432\u0430 \u0442\u0440\u0438' . split ( )
|
512 | sort query set by number of characters in a field `length` in django model `MyModel`
| MyModel . objects . extra ( select = { 'length' : 'Length(name)' } ) . order_by ( 'length' )
|
513 | get a dictionary in list `dicts` which key 'ratio' is closer to a global value 1.77672955975
| min ( dicts , key = lambda x : ( abs ( 1.77672955975 - x [ 'ratio' ] ) , - x [ 'pixels' ] ) )
|
514 | get the non-masked values of array `m`
| m [ ~ m . mask ]
|
515 | Find all words containing letters between A and Z in string `formula`
| re . findall ( '\\b[A-Z]' , formula )
|
516 | create a list `matrix` containing 5 lists, each of 5 items all set to 0
| matrix = [ ( [ 0 ] * 5 ) for i in range ( 5 ) ]
|
517 | creating a numpy array of 3d coordinates from three 1d arrays `x_p`, `y_p` and `z_p`
| np . vstack ( np . meshgrid ( x_p , y_p , z_p ) ) . reshape ( 3 , - 1 ) . T
|
518 | find the minimum value in a numpy array `arr` excluding 0
| arr [ arr != 0 ] . min ( )
|
519 | get the text of multiple elements found by xpath "//*[@type='submit']/@value"
| browser . find_elements_by_xpath ( "//*[@type='submit']/@value" ) . text
|
520 | find all the values in attribute `value` for the tags whose `type` attribute is `submit` in selenium
| browser . find_elements_by_xpath ( "//*[@type='submit']" ) . get_attribute ( 'value' )
|
521 | parse a YAML file "example.yaml"
| with open ( 'example.yaml' , 'r' ) as stream : try : print ( ( yaml . load ( stream ) ) ) except yaml . YAMLError as exc : print ( exc )
|
522 | parse a YAML file "example.yaml"
| with open ( 'example.yaml' ) as stream : try : print ( ( yaml . load ( stream ) ) ) except yaml . YAMLError as exc : print ( exc )
|
523 | Sort the values of the dataframe `df` and align the columns accordingly based on the obtained indices after np.argsort.
| pd . DataFrame ( df . columns [ np . argsort ( df . values ) ] , df . index , np . unique ( df . values ) )
|
524 | Getting today's date in YYYY-MM-DD
| datetime . datetime . today ( ) . strftime ( '%Y-%m-%d' )
|
525 | urlencode a querystring 'string_of_characters_like_these:$#@=?%^Q^$' in python 2
| urllib . parse . quote_plus ( 'string_of_characters_like_these:$#@=?%^Q^$' )
|
526 | sort a dictionary `d` by length of its values and print as string
| print ( ' ' . join ( sorted ( d , key = lambda k : len ( d [ k ] ) , reverse = True ) ) )
|
527 | convert tuple elements in list `[(1,2),(3,4),(5,6),]` into lists
| map ( list , zip ( * [ ( 1 , 2 ) , ( 3 , 4 ) , ( 5 , 6 ) ] ) )
|
528 | convert list of tuples to multiple lists in Python
| map ( list , zip ( * [ ( 1 , 2 ) , ( 3 , 4 ) , ( 5 , 6 ) ] ) )
|
529 | convert list of tuples to multiple lists in Python
| zip ( * [ ( 1 , 2 ) , ( 3 , 4 ) , ( 5 , 6 ) ] )
|
530 | create a list of tuples which contains number 9 and the number before it, for each occurrence of 9 in the list 'myList'
| [ ( x , y ) for x , y in zip ( myList , myList [ 1 : ] ) if y == 9 ]
|
531 | navigate to webpage given by url `http://www.python.org` using Selenium
| driver . get ( 'http://www.google.com.br' )
|
532 | reverse a UTF-8 string 'a'
| b = a . decode ( 'utf8' ) [ : : - 1 ] . encode ( 'utf8' )
|
533 | extract date from a string 'monkey 2010-07-32 love banana'
| dparser . parse ( 'monkey 2010-07-32 love banana' , fuzzy = True )
|
534 | extract date from a string 'monkey 20/01/1980 love banana'
| dparser . parse ( 'monkey 20/01/1980 love banana' , fuzzy = True )
|
535 | extract date from a string `monkey 10/01/1980 love banana`
| dparser . parse ( 'monkey 10/01/1980 love banana' , fuzzy = True )
|
536 | Convert a list `['A:1', 'B:2', 'C:3', 'D:4']` to dictionary
| dict ( map ( lambda s : s . split ( ':' ) , [ 'A:1' , 'B:2' , 'C:3' , 'D:4' ] ) )
|
537 | check if string `the_string` contains any upper or lower-case ASCII letters
| re . search ( '[a-zA-Z]' , the_string )
|
538 | convert a pandas `df1` groupby object to dataframe
| DataFrame ( { 'count' : df1 . groupby ( [ 'Name' , 'City' ] ) . size ( ) } ) . reset_index ( )
|
539 | remove all non-numeric characters from string `sdkjh987978asd098as0980a98sd `
| re . sub ( '[^0-9]' , '' , 'sdkjh987978asd098as0980a98sd' )
|
540 | get items from list `a` that don't appear in list `b`
| [ y for y in a if y not in b ]
|
541 | extract the first four rows of the column `ID` from a pandas dataframe `df`
| df . groupby ( 'ID' ) . head ( 4 )
|
542 | Unzip a list of tuples `l` into a list of lists
| zip ( * l )
|
543 | combine two lists `[1, 2, 3, 4]` and `['a', 'b', 'c', 'd']` into a dictionary
| dict ( zip ( [ 1 , 2 , 3 , 4 ] , [ 'a' , 'b' , 'c' , 'd' ] ) )
|
544 | combine two lists `[1, 2, 3, 4]` and `['a', 'b', 'c', 'd']` into a dictionary
| dict ( zip ( [ 1 , 2 , 3 , 4 ] , [ 'a' , 'b' , 'c' , 'd' ] ) )
|
545 | retrieve the path from a Flask request
| request . url
|
546 | replace carriage return in string `somestring` with empty string ''
| somestring . replace ( '\\r' , '' )
|
547 | serialize dictionary `d` as a JSON formatted string with each key formatted to pattern '%d,%d'
| simplejson . dumps ( dict ( [ ( '%d,%d' % k , v ) for k , v in list ( d . items ( ) ) ] ) )
|
548 | parse string "Jun 1 2005 1:33PM" into datetime by format "%b %d %Y %I:%M%p"
| datetime . strptime ( 'Jun 1 2005 1:33PM' , '%b %d %Y %I:%M%p' )
|
549 | parse string "Aug 28 1999 12:00AM" into datetime
| parser . parse ( 'Aug 28 1999 12:00AM' )
|
550 | Get absolute folder path and filename for file `existGDBPath `
| os . path . split ( os . path . abspath ( existGDBPath ) )
|
551 | extract folder path from file path
| os . path . dirname ( os . path . abspath ( existGDBPath ) )
|
552 | Execute a post request to url `http://httpbin.org/post` with json data `{'test': 'cheers'}`
| requests . post ( 'http://httpbin.org/post' , json = { 'test' : 'cheers' } )
|
553 | remove dictionary from list `a` if the value associated with its key 'link' is in list `b`
| a = [ x for x in a if x [ 'link' ] not in b ]
|
554 | get a request parameter `a` in jinja2
| { { request . args . get ( 'a' ) } }
|
555 | create a list of integers between 2 values `11` and `17`
| list ( range ( 11 , 17 ) )
|
556 | Change data type of data in column 'grade' of dataframe `data_df` into float and then to int
| data_df [ 'grade' ] = data_df [ 'grade' ] . astype ( float ) . astype ( int )
|
557 | Find the list in a list of lists `alkaline_earth_values` with the max value of the second element.
| max ( alkaline_earth_values , key = lambda x : x [ 1 ] )
|
558 | remove leading and trailing zeros in the string 'your_Strip'
| your_string . strip ( '0' )
|
559 | generate a list of all unique pairs of integers in `range(9)`
| list ( permutations ( list ( range ( 9 ) ) , 2 ) )
|
560 | create a regular expression that matches the pattern '^(.+)(?:\\n|\\r\\n?)((?:(?:\\n|\\r\\n?).+)+)' over multiple lines of text
| re . compile ( '^(.+)(?:\\n|\\r\\n?)((?:(?:\\n|\\r\\n?).+)+)' , re . MULTILINE )
|
561 | regular expression "^(.+)\\n((?:\\n.+)+)" matching a multiline block of text
| re . compile ( '^(.+)\\n((?:\\n.+)+)' , re . MULTILINE )
|
562 | Run 'test2.py' file with python location 'path/to/python' and arguments 'neededArgumetGoHere' as a subprocess
| call ( [ 'path/to/python' , 'test2.py' , 'neededArgumetGoHere' ] )
|
563 | sort a multidimensional list `a` by second and third column
| a . sort ( key = operator . itemgetter ( 2 , 3 ) )
|
564 | Add a tuple with value `another_choice` to a tuple `my_choices`
| final_choices = ( ( another_choice , ) + my_choices )
|
565 | Add a tuple with value `another_choice` to a tuple `my_choices`
| final_choices = ( ( another_choice , ) + my_choices )
|
566 | find the current directory
| os . getcwd ( )
|
567 | find the current directory
| os . path . realpath ( __file__ )
|
568 | get the directory name of `path`
| os . path . dirname ( path )
|
569 | get the canonical path of file `path`
| os . path . realpath ( path )
|
570 | Find name of current directory
| dir_path = os . path . dirname ( os . path . realpath ( __file__ ) )
|
571 | Find current directory
| cwd = os . getcwd ( )
|
572 | Find the full path of current directory
| full_path = os . path . realpath ( __file__ )
|
573 | sort array `arr` in ascending order by values of the 3rd column
| arr [ arr [ : , ( 2 ) ] . argsort ( ) ]
|
574 | sort rows of numpy matrix `arr` in ascending order according to all column values
| numpy . sort ( arr , axis = 0 )
|
575 | split string 'a b.c' on space " " and dot character "."
| re . split ( '[ .]' , 'a b.c' )
|
576 | copy the content of file 'file.txt' to file 'file2.txt'
| shutil . copy ( 'file.txt' , 'file2.txt' )
|
577 | generate random upper-case ascii string of 12 characters length
| print ( '' . join ( choice ( ascii_uppercase ) for i in range ( 12 ) ) )
|
578 | merge the elements in a list `lst` sequentially
| [ '' . join ( seq ) for seq in zip ( lst , lst [ 1 : ] ) ]
|
579 | rename column 'gdp' in dataframe `data` to 'log(gdp)'
| data . rename ( columns = { 'gdp' : 'log(gdp)' } , inplace = True )
|
580 | convert a beautiful soup html `soup` to text
| print ( soup . get_text ( ) )
|
581 | Sort list `li` in descending order based on the second element of each list inside list`li`
| sorted ( li , key = operator . itemgetter ( 1 ) , reverse = True )
|
582 | replace value 0 with 'Female' and value 1 with 'Male' in column 'sex' of dataframe `data`
| data [ 'sex' ] . replace ( [ 0 , 1 ] , [ 'Female' , 'Male' ] , inplace = True )
|
583 | split string 'Words, words, words.' on punctuation
| re . split ( '\\W+' , 'Words, words, words.' )
|
584 | Extract first two substrings in string `phrase` that end in `.`, `?` or `!`
| re . match ( '(.*?[.?!](?:\\s+.*?[.?!]){0,1})' , phrase ) . group ( 1 )
|
585 | split string `s` into strings of repeating elements
| print ( [ a for a , b in re . findall ( '((\\w)\\2*)' , s ) ] )
|
586 | Create new string with unique characters from `s` seperated by ' '
| print ( ' ' . join ( OrderedDict . fromkeys ( s ) ) )
|
587 | create a set from string `s` to remove duplicate characters
| print ( ' ' . join ( set ( s ) ) )
|
588 | list folders in zip file 'file' that ends with '/'
| [ x for x in file . namelist ( ) if x . endswith ( '/' ) ]
|
589 | find the count of a word 'Hello' in a string `input_string`
| input_string . count ( 'Hello' )
|
590 | reduce the first element of list of strings `data` to a string, separated by '.'
| print ( '.' . join ( [ item [ 0 ] for item in data ] ) )
|
591 | Move the cursor of file pointer `fh1` at the end of the file.
| fh1 . seek ( 2 )
|
592 | convert a flat list into a list of tuples of every two items in the list, in order
| print ( zip ( my_list [ 0 : : 2 ] , my_list [ 1 : : 2 ] ) )
|
593 | group a list of ints into a list of tuples of each 2 elements
| my_new_list = zip ( my_list [ 0 : : 2 ] , my_list [ 1 : : 2 ] )
|
594 | set the default encoding to 'utf-8'
| sys . setdefaultencoding ( 'utf8' )
|
595 | Formate current date and time to a string using pattern '%Y-%m-%d %H:%M:%S'
| datetime . datetime . now ( ) . strftime ( '%Y-%m-%d %H:%M:%S' )
|
596 | retrieve arabic texts from string `my_string`
| print ( re . findall ( '[\\u0600-\\u06FF]+' , my_string ) )
|
597 | group dataframe `df` based on minute interval
| df . groupby ( df . index . map ( lambda t : t . minute ) )
|
598 | access value associated with key 'American' of key 'Apple' from dictionary `dict`
| dict [ 'Apple' ] [ 'American' ]
|
599 | remove all null values from columns 'three', 'four' and 'five' of dataframe `df2`
| df2 . dropna ( subset = [ 'three' , 'four' , 'five' ] , how = 'all' )
|