text
stringlengths 4
1.08k
|
|---|
"get the first row, second column; second row, first column, and first row third column values of numpy array `arr`","arr[[0, 1, 1], [1, 0, 2]]"
|
create a list with permutations of string 'abcd',list(powerset('abcd'))
|
Convert string to boolean from defined set of strings,"s in ['true', '1', 't', 'y', 'yes', 'yeah', 'yup', 'certainly', 'uh-huh']"
|
replace special characters in url 'http://spam.com/go/' using the '%xx' escape,urllib.parse.quote('http://spam.com/go/')
|
Save plot `plt` as svg file 'test.svg',plt.savefig('test.svg')
|
count the number of elements in array `myArray`,len(myArray)
|
insert directory './path/to/your/modules/' to current directory,"sys.path.insert(0, './path/to/your/modules/')"
|
"Insert records in bulk from ""table1"" of ""master"" DB to ""table1"" of sqlite3 `cursor` object",cursor.execute('INSERT OR REPLACE INTO master.table1 SELECT * FROM table1')
|
Match regex '[a-zA-Z][\\w-]*\\Z' on string 'A\n',"re.match('[a-zA-Z][\\w-]*\\Z', 'A\n')"
|
match regex '[a-zA-Z][\\w-]*$' on string '!A_B',"re.match('[a-zA-Z][\\w-]*$', '!A_B')"
|
"Convert hex string ""deadbeef"" to integer","int('deadbeef', 16)"
|
"Convert hex string ""a"" to integer","int('a', 16)"
|
"Convert hex string ""0xa"" to integer","int('0xa', 16)"
|
Convert hex string `s` to integer,"int(s, 16)"
|
Convert hex string `hexString` to int,"int(hexString, 16)"
|
print variable `value ` without spaces,"print('Value is ""' + str(value) + '""')"
|
Print a string `value` with string formatting,"print('Value is ""{}""'.format(value))"
|
Jinja join elements of array `tags` with space string ' ',{{tags | join(' ')}}
|
get a list of locally installed Python modules,help('modules')
|
Get only first element in each of the innermost of the multidimensional list `listD`,[[[x[0]] for x in listD[i]] for i in range(len(listD))]
|
Sort a string `s` in lexicographic order,"sorted(s, key=str.upper)"
|
sort string `s` in lexicographic order,"sorted(sorted(s), key=str.upper)"
|
"get a sorted list of the characters of string `s` in lexicographic order, with lowercase letters first","sorted(s, key=str.lower)"
|
"find all the rows in Dataframe 'df2' that are also present in Dataframe 'df1', for the columns 'A', 'B', 'C' and 'D'.","pd.merge(df1, df2, on=['A', 'B', 'C', 'D'], how='inner')"
|
Reverse key-value pairs in a dictionary `map`,"dict((v, k) for k, v in map.items())"
|
decode unicode string `s` into a readable unicode literal,s.decode('unicode_escape')
|
convert list of strings `str_list` into list of integers,[int(i) for i in str_list]
|
"convert a list with string `['1', '2', '3']` into list with integers","map(int, ['1', '2', '3'])"
|
convert list with str into list with int,"list(map(int, ['1', '2', '3']))"
|
find all anchor tags in html `soup` whose url begins with `http://www.iwashere.com`,"soup.find_all('a', href=re.compile('http://www\\.iwashere\\.com/'))"
|
find all anchors with a hyperlink that matches the pattern '^(?!(?:[a-zA-Z][a-zA-Z0-9+.-]*:|//))',"soup.find_all('a', href=re.compile('^(?!(?:[a-zA-Z][a-zA-Z0-9+.-]*:|//))'))"
|
execute a jar file 'Blender.jar' using subprocess,"subprocess.call(['java', '-jar', 'Blender.jar'])"
|
insert row into mysql database with column 'column1' set to the value `value`,"cursor.execute('INSERT INTO table (`column1`) VALUES (%s)', (value,))"
|
"remove a substring "".com"" from the end of string `url`","if url.endswith('.com'):
|
url = url[:(-4)]"
|
"remove a substring "".com"" from the end of string `url`","url = re.sub('\\.com$', '', url)"
|
"remove a substring "".com"" from the end of string `url`","print(url.replace('.com', ''))"
|
remove a substring `suffix` from the end of string `text`,"if (not text.endswith(suffix)):
|
return text
|
return text[:(len(text) - len(suffix))]"
|
print each first value from a list of tuples `mytuple` with string formatting,"print(', ,'.join([str(i[0]) for i in mytuple]))"
|
clamping floating number `my_value` to be between `min_value` and `max_value`,"max(min(my_value, max_value), min_value)"
|
split a unicode string `text` into a list of words and punctuation characters with a regex,"re.findall('\\w+|[^\\w\\s]', text, re.UNICODE)"
|
execute raw sql queue '<sql here>' in database `db` in sqlalchemy-flask app,result = db.engine.execute('<sql here>')
|
quit program,sys.exit(0)
|
get digits in string `my_string`,""""""""""""".join(c for c in my_string if c.isdigit())"
|
split string `str1` on one or more spaces with a regular expression,"re.split(' +', str1)"
|
Evaluate a nested dictionary `myobject.id.number` to get `number` if `myobject` is present with getattr,"getattr(getattr(myobject, 'id', None), 'number', None)"
|
convert generator object to a dictionary,{i: (i * 2) for i in range(10)}
|
convert generator object to a dictionary,"dict((i, i * 2) for i in range(10))"
|
Matplotlib clear the current axes.,plt.cla()
|
split string `s` into float values and write sum to `total`,"total = sum(float(item) for item in s.split(','))"
|
Convert ascii value 'P' to binary,bin(ord('P'))
|
"print a string after a specific substring ', ' in string `my_string `","print(my_string.split(', ', 1)[1])"
|
get value of key `post code` associated with first index of key `places` of dictionary `data`,print(data['places'][0]['post code'])
|
remove colon character surrounded by vowels letters in string `word`,"word = re.sub('([aeiou]):(([aeiou][^aeiou]*){3})$', '\\1\\2', word)"
|
extract data field 'bar' from json object,"json.loads('{""foo"": 42, ""bar"": ""baz""}')['bar']"
|
Convert JSON array `array` to Python object,data = json.loads(array)
|
Convert JSON array `array` to Python object,data = json.loads(array)
|
pars a string 'http://example.org/#comments' to extract hashtags into an array,"re.findall('#(\\w+)', 'http://example.org/#comments')"
|
do a boolean check if a string `lestring` contains any of the items in list `lelist`,any(e in lestring for e in lelist)
|
Parsing HTML string `html` using BeautifulSoup,"parsed_html = BeautifulSoup(html)
|
print(parsed_html.body.find('div', attrs={'class': 'container', }).text)"
|
Parsing webpage 'http://www.google.com/' using BeautifulSoup,"page = urllib.request.urlopen('http://www.google.com/')
|
soup = BeautifulSoup(page)"
|
change figure size to 3 by 4 in matplotlib,"plt.figure(figsize=(3, 4))"
|
Strip punctuation from string `s`,"s.translate(None, string.punctuation)"
|
django urlsafe base64 decode string `uenc` with decryption,base64.urlsafe_b64decode(uenc.encode('ascii'))
|
get the number of all keys in the nested dictionary `dict_list`,len(dict_test) + sum(len(v) for v in dict_test.values())
|
return the conversion of decimal `d` to hex without the '0x' prefix,hex(d).split('x')[1]
|
create a list containing digits of number 123 as its elements,list(str(123))
|
converting integer `num` to list,[int(x) for x in str(num)]
|
select a first form with no name in mechanize,br.select_form(nr=0)
|
Open file 'sample.json' in read mode with encoding of 'utf-8-sig',"json.load(codecs.open('sample.json', 'r', 'utf-8-sig'))"
|
load json file 'sample.json' with utf-8 bom header,json.loads(open('sample.json').read().decode('utf-8-sig'))
|
setup a smtp mail server to `smtp.gmail.com` with port `587`,"server = smtplib.SMTP('smtp.gmail.com', 587)"
|
revers correlating bits of integer `n`,"int('{:08b}'.format(n)[::-1], 2)"
|
add column `d` to index of dataframe `df`,"df.set_index(['d'], append=True)"
|
Iterating over a dictionary `d` using for loops,"for (key, value) in d.items():
|
pass"
|
Iterating over a dictionary `d` using for loops,"for (key, value) in list(d.items()):
|
pass"
|
Iterating key and items over dictionary `d`,"for (letter, number) in list(d.items()):
|
pass"
|
Iterating key and items over dictionary `d`,"for (k, v) in list(d.items()):
|
pass"
|
get keys and items of dictionary `d`,list(d.items())
|
get keys and items of dictionary `d` as a list,list(d.items())
|
Iterating key and items over dictionary `d`,"for (k, v) in list(d.items()):
|
pass"
|
Iterating key and items over dictionary `d`,"for (letter, number) in list(d.items()):
|
pass"
|
Iterating key and items over dictionary `d`,"for (letter, number) in list(d.items()):
|
pass"
|
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()
|
compile Visual Studio project `project.sln` from the command line through python,os.system('msbuild project.sln /p:Configuration=Debug')
|
get max key in dictionary `MyCount`,"max(list(MyCount.keys()), key=int)"
|
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')
|
get a name of function `my_function` as a string,my_function.__name__
|
check if all values in the columns of a numpy matrix `a` are same,"np.all(a == a[(0), :], axis=0)"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.