text
stringlengths 4
1.08k
|
|---|
how to draw line inside a scatter plot,ax.set_title('ROC Space')
|
any way to properly pretty-print ordered dictionaries in python?,pprint(dict(list(o.items())))
|
how to implement autovivification for nested dictionary only when assigning values?,my_dict[1][2] = 3
|
sorting a list in python,"sorted(words, key=lambda x: 'a' + x if x[:1] == 's' else 'b' + x)"
|
replacing values greater than a limit in a numpy array,"np.array([[0, 1, 2, 3], [4, 5, 4, 3], [6, 5, 4, 3]])"
|
case-insensitive string startswith in python,"bool(re.match('el', 'Hello', re.I))"
|
using savepoints in python sqlite3,"conn.execute('insert into example values (?, ?);', (2, 202))"
|
python list comprehension for loops,[(x + y) for x in '12345' for y in 'abc']
|
how to wrap a c++ function which takes in a function pointer in python using swig,test.f(0)
|
reverse indices of a sorted list,"sorted(x[::-1] for x in enumerate(['z', 'a', 'c', 'x', 'm']))"
|
how to convert strings numbers to integers in a list?,changed_list = [(int(f) if f.isdigit() else f) for f in original_list]
|
reverse y-axis in pyplot,plt.gca().invert_xaxis()
|
access an arbitrary element in a dictionary in python,next(iter(list(dict.values())))
|
how can i scroll a web page using selenium webdriver in python?,"driver.execute_script('window.scrollTo(0, Y)')"
|
how to calculate a partial area under the curve (auc),"plot([0, 0.5], [0.5, 0.5], [0.5, 0.5], [0.5, 1], [0.5, 1], [1, 1])"
|
how to input a word in ncurses screen?,curses.endwin()
|
terminate the script using status value 0,sys.exit(0)
|
count the number of pairs in dictionary `d` whose value equal to `chosen_value`,sum(x == chosen_value for x in list(d.values()))
|
"create a django query for a list of values `1, 4, 7`","Blog.objects.filter(pk__in=[1, 4, 7])"
|
get ip address in google app engine + python,os.environ['REMOTE_ADDR']
|
substitute multiple whitespace with single whitespace in string `mystring`,""""""" """""".join(mystring.split())"
|
generate a n-dimensional array of coordinates in numpy,"ndim_grid([2, -2, 4], [5, 3, 6])"
|
getting every possible combination of two elements in a list,"list(itertools.combinations([1, 2, 3, 4, 5, 6], 2))"
|
"python 2.7 - find and replace from text file, using dictionary, to new text file","output = open('output_test_file.txt', 'w')"
|
extract number from string - python,int(str1.split()[0])
|
close a tkinter window?,root.quit()
|
run a .bat program in the background on windows,time.sleep(1)
|
what is the proper way to insert an object with a foreign key in sqlalchemy?,transaction.commit()
|
normalizing colors in matplotlib,plt.show()
|
sorting a list of dicts by dict values,"sorted(a, key=lambda i: list(i.values())[0], reverse=True)"
|
extract day of year and julian day from a string date in python,"int(sum(jdcal.gcal2jd(dt.year, dt.month, dt.day)))"
|
sort list `strings` in alphabetical order based on the letter after percent character `%` in each element,"strings.sort(key=lambda str: re.sub('.*%(.).*', '\\1', str))"
|
how to change fontsize in excel using python,"style = xlwt.easyxf('font: bold 1,height 280;')"
|
pandas: counting unique values in a dataframe,"d.apply(pd.Series.value_counts, axis=1).fillna(0)"
|
surface plots in matplotlib,plt.show()
|
how to find the count of a word in a string?,input_string.count('Hello')
|
"python: rstrip one exact string, respecting order","""""""Boat.txt.txt"""""".replace('.txt', '')"
|
map two lists into a dictionary in python,"list(zip(keys, values))"
|
how to avoid overlapping of labels & autopct in a matplotlib pie chart?,"plt.savefig('piechart.png', bbox_inches='tight')"
|
how to split a string at line breaks in python?,"[map(int, x.split('\t')) for x in s.rstrip().split('\r\n')]"
|
combining two lists into a list of lists,"[('1', '11'), ('2', '22'), ('', '33'), ('', '44')]"
|
python split semantics in java,str.trim().split('\\s+')
|
get keys with same value in dictionary `d`,"print([key for key, value in d.items() if value == 1])"
|
test if a class is inherited from another,"self.assertTrue(issubclass(QuizForm, forms.Form))"
|
how to remove 0's converting pandas dataframe to record,df.to_sparse(0)
|
python: find only common key-value pairs of several dicts: dict intersection,dict(set.intersection(*(set(d.items()) for d in dicts)))
|
"calling an external command ""echo hello world""","return_code = subprocess.call('echo Hello World', shell=True)"
|
"pandas read_csv expects wrong number of columns, with ragged csv file","pd.read_csv('D:/Temp/tt.csv', names=list('abcdef'))"
|
find the selected option using beautifulsoup,"soup.find_all('option', {'selected': True})"
|
how to sort a list by checking values in a sublist in python?,"sorted(L, key=itemgetter(1), reverse=True)"
|
finding consecutive consonants in a word,"re.findall('[bcdfghjklmnpqrstvwxyz]+', 'concertation', re.IGNORECASE)"
|
deleting rows in numpy array,"x = array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])"
|
how to crop an image in opencv using python,cv2.waitKey(0)
|
how to create a comprehensible bar chart with matplotlib for more than 100 values?,plt.title('Utilisateur')
|
sum values from dataframe into parent index - python/pandas,"df_new.reset_index().set_index(['parent', 'index']).sort_index()"
|
python concatenate string & list,""""""", """""".join(str(f) for f in fruits)"
|
"python, format string ""{} %s {}"" to have 'foo' and 'bar' in the first and second positions","""""""{} %s {}"""""".format('foo', 'bar')"
|
how do i set color to rectangle in matplotlib?,plt.show()
|
how do i construct and populate a wx.grid with data from a database (python/wxpython),"mygrid.SetCellValue(row, col, databasevalue4rowcol)"
|
python sum of ascii values of all characters in a string `string`,"sum(map(ord, string))"
|
split list `mylist` into a list of lists whose elements have the same first five characters,"[list(v) for k, v in itertools.groupby(mylist, key=lambda x: x[:5])]"
|
python regular expression match,print(m.group(1))
|
using 'if in' with a dictionary,any(value in dictionary[key] for key in dictionary)
|
"updating a list of python dictionaries with a key, value pair from another list","[dict(d, count=n) for d, n in zip(l1, l2)]"
|
python/regex - expansion of parentheses and slashes,"['1', '(15/-23)s', '4']"
|
how can i retrieve the tls/ssl peer certificate of a remote host using python?,"print(ssl.get_server_certificate(('server.test.com', 443)))"
|
get a list of the lowest subdirectories in a tree,"[os.path.split(r)[-1] for r, d, f in os.walk(tree) if not d]"
|
convert a list of strings to either int or float,[(int(i) if i.isdigit() else float(i)) for i in s]
|
python & pandas: how to query if a list-type column contains something?,df[df.genre.str.join(' ').str.contains('comedy')]
|
python loop dictionary items through a tkinter gui using a button,"L.grid(row=6, column=0)"
|
selecting a subset of functions from a list of functions in python,"return map(lambda f: f(*args), funcs)"
|
convert a list to a dictionary in python,"{'bi': 2, 'double': 2, 'duo': 2, 'two': 2}"
|
getting data from ctypes array into numpy,"a = numpy.frombuffer(buffer, float)"
|
calculating power for decimals in python,"decimal.power(Decimal('2'), Decimal('2.5'))"
|
print unicode characters in a string `\u0420\u043e\u0441\u0441\u0438\u044f`,print('\u0420\u043e\u0441\u0441\u0438\u044f')
|
convert a list into a nested dictionary,print(d['a']['b']['c'])
|
python - how to calculate equal parts of two dictionaries?,"d3 = {k: v for k, v in list(d3.items()) if v}"
|
get value in string `line` matched by regex pattern '\\blog_addr\\s+(\\s+)',"print(re.search('\\bLOG_ADDR\\s+(\\S+)', line).group(1))"
|
how can i get the color of the last figure in matplotlib?,"ebar = plt.errorbar(x, y, yerr=err, ecolor='y')"
|
how to transform a tuple to a string of values without comma and parentheses,""""""" """""".join(map(str, (34.2424, -64.2344, 76.3534, 45.2344)))"
|
writing items in list `thelist` to file `thefile`,"for item in thelist:
|
pass"
|
python split function -avoids last empy space,[x for x in my_str.split(';') if x]
|
convert `a` to string,a.__str__()
|
matplotlib: set markers for individual points on a line,"plt.plot(list(range(10)), linestyle='--', marker='o', color='b')"
|
what is a simple fuzzy string matching algorithm in python?,"difflib.SequenceMatcher(None, a, b).ratio()"
|
python: dots in the name of variable in a format string,print('Name: %(person.name)s' % {'person.name': 'Joe'})
|
replace a string located between,"re.sub(',(?=[^][]*\\])', '', str)"
|
best way to extract subset of key-value pairs from python dictionary object,"{k: bigdict[k] for k in list(bigdict.keys()) & {'l', 'm', 'n'}}"
|
how do i set proxy for chrome in python webdriver,driver.get('http://whatismyip.com')
|
how to authenticate a public key with certificate authority using python?,"requests.get(url, verify=True)"
|
joining pairs of elements of a list - python,"[(i + j) for i, j in zip(x[::2], x[1::2])]"
|
matplotlib: set markers for individual points on a line,"plt.plot(list(range(10)), '--bo')"
|
how to write a dictionary into a file?,input_file.close()
|
remove duplicate dict in list in python,[dict(t) for t in set([tuple(d.items()) for d in l])]
|
pandas pivot table of sales,"pd.crosstab(df.saleid, df.upc)"
|
"python-social-auth and django, replace usersocialauth with custom model",SOCIAL_AUTH_STORAGE = 'proj.channels.models.CustomSocialStorage'
|
call a function with argument list in python,func(*args)
|
how to implement server push in flask framework?,app.run(threaded=True)
|
django - get only date from datetime.strptime,"datetime.strptime('2014-12-04', '%Y-%m-%d').date()"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.