text
stringlengths 4
1.08k
|
|---|
how do i add space between two variables after a print in python,"print('{0} {1}'.format(count, conv))"
|
matplotlib: text color code in the legend instead of a line,plt.show()
|
create 2d array in python using for loop results,"[[i, i * 10] for i in range(5)]"
|
cannot return results from stored procedure using python cursor,"cursor.callproc('getperson', ['1'])"
|
how can i access namespaced xml elements using beautifulsoup?,print(doc.find('web:offset').string)
|
how to unit-test post request for multiple checkboxes with the same name under webapp2,"urllib.parse.urlencode({'vote': ['Better', 'Faster', 'Stronger']}, True)"
|
sort list `keys` based on its elements' dot-seperated numbers,"keys.sort(key=lambda x: map(int, x.split('.')))"
|
string slugification in python,"self.assertEqual(r, 'jaja-lol-mememeoo-a')"
|
pipe output from shell command to a python script,print(sys.stdin.read())
|
find out if there is input from a pipe or not in python?,sys.stdin.isatty()
|
sorting list of tuples by arbitrary key,"sorted(mylist, key=lambda x: order.index(x[1]))"
|
replace printed statements in python 2.7,sys.stdout.flush()
|
print all environment variables,print(os.environ)
|
how do i access a object's method when the method's name is in a variable?,"getattr(test, method)"
|
how to scrape a website that requires login first with python,br.set_handle_robots(False)
|
python datetime to microtime,time.mktime(dt.timetuple()) + dt.microsecond / 1000000.0
|
extract only characters from a string as a list,"re.split('[^a-zA-Z]*', 'your string')"
|
parse string '21/11/06 16:30' according to format '%d/%m/%y %h:%m',"datetime.strptime('21/11/06 16:30', '%d/%m/%y %H:%M')"
|
matplotlib legend showing double errorbars,plt.legend(numpoints=1)
|
how to pass arguments as tuple to odeint?,"odeint(func, y0, t, a, b, c)"
|
concatenate row values for the same index in pandas,"df.groupby('A').apply(lambda x: list(np.repeat(x['B'].values, x['quantity'])))"
|
select the last business day of the month for each month in 2014 in pandas,"pd.date_range('1/1/2014', periods=12, freq='BM')"
|
finding index of the same elements in a list,"[index for index, letter in enumerate(word) if letter == 'e']"
|
what's the best way to search for a python dictionary value in a list of dictionaries?,any(d['site'] == 'Superuser' for d in data)
|
changing image hue with python pil,new_img.save('tweeter_red.png')
|
how to assert a dict contains another dict without assertdictcontainssubset in python?,set(d1.items()).issubset(set(d2.items()))
|
python - json without whitespaces,"json.dumps(separators=(',', ':'))"
|
python getting a list of value from list of dict,"map(lambda d: d.get('value', 'default value'), l)"
|
hexagonal self-organizing map in python,"(i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j - 1), (i + 1, j + 1)"
|
elegantly changing the color of a plot frame in matplotlib,"plt.setp([ax.get_xticklines(), ax.get_yticklines()], color=color)"
|
generate a heatmap in matplotlib using a scatter data set,plt.show()
|
how can i use the python imaging library to create a bitmap,img.show()
|
print a string as hex bytes?,""""""":"""""".join(x.encode('hex') for x in 'Hello World!')"
|
python logging module: custom loggers,logging.getLogger('foo')
|
how to do a regex replace with matching case?,"re.sub('\\bfoo\\b', cased_replacer('bar'), 'this is foo', flags=re.I)"
|
argparse: how to handle variable number of arguments (nargs='*'),"spp1.add_argument('vars', nargs='*')"
|
how to dynamically load a python class,my_import('foo.bar.baz.qux')
|
python import a module from a directory(package) one level up,sys.path.append('../..')
|
python: shifting elements in a list to the right and shifting the element at the end of the list to the beginning,"[5, 1, 2, 3, 4]"
|
regex: how to match words without consecutive vowels?,"[w for w in open('file.txt') if not re.search('[aeiou]{2}', w)]"
|
matplotlib plot with variable line width,fig.show()
|
iterate over the lines of a string,"return map(lambda s: s.strip('\n'), stri)"
|
how does numpy infers dtype for array,"np.array(12345678901234, dtype=np.int32)"
|
rreplace - how to replace the last occurence of an expression in a string?,"re.sub('(.*)</div>', '\\1</bad>', s)"
|
delete multiple dictionaries in a list,[i for i in Records if i['Price']]
|
concise way to remove elements from list by index in python,"[v for i, v in enumerate(myList) if i not in toRemove]"
|
how to convert comma-delimited string to list in python?,print(tuple(my_list))
|
python/pandas: how to combine two dataframes into one with hierarchical column index?,"pd.concat(dict(df1=df1, df2=df2), axis=1)"
|
python - subprocess - how to call a piped command in windows?,"subprocess.call(['ECHO', 'Ni'], shell=True)"
|
how to animate the colorbar in matplotlib,plt.show()
|
how to sort ordereddict of ordereddict - python,"OrderedDict(sorted(list(od.items()), key=lambda item: item[1]['depth']))"
|
python - find text using beautifulsoup then replace in original soup variable,findtoure = commentary.find(text=re.compile('Yaya Toure'))
|
how do i suppress scientific notation in python?,'%f' % (x / y)
|
comparing elements between elements in two lists of tuples,set(x[0] for x in list1).intersection(y[0] for y in list2)
|
convert all of the items in a list `lst` to float,[float(i) for i in lst]
|
pandas: how to increment a column's cell value based on a list of ids,"my_df.loc[my_df['id'].isin(ids), 'other_column'] += 1"
|
removing characters from string python,""""""""""""".join(c for c in text if c not in 'aeiouAEIOU')"
|
selenium with pyvirtualdisplay unable to locate element,content = browser.find_element_by_id('content')
|
summarizing a dictionary of arrays in python,"sorted(iter(mydict.items()), key=lambda k_v: sum(k_v[1]), reverse=True)[:3]"
|
how do i convert an array to string using the jinja template engine?,{{tags | join(' ')}}
|
using python string formatting with lists,""""""", """""".join(['%.2f'] * len(x))"
|
load a file `file.py` into the python console,"exec(compile(open('file.py').read(), 'file.py', 'exec'))"
|
calcuate mean for selected rows for selected columns in pandas data frame,"df.iloc[:, ([2, 5, 6, 7, 8])].mean(axis=0)"
|
numpy: cartesian product of x and y array points into single array of 2d points,"numpy.dstack(numpy.meshgrid(x, y)).reshape(-1, 2)"
|
conditional row read of csv in pandas,df[df['B'] > 10]
|
remove all whitespaces in a string `sentence`,sentence = ''.join(sentence.split())
|
how do i integrate ajax with django applications?,"return render_to_response('index.html', {'variable': 'world'})"
|
how to alphabetically sort array of dictionaries on single key?,my_list.sort(key=operator.itemgetter('name'))
|
"calling an external command ""ls -l""",from subprocess import call
|
rotate axis text in python matplotlib,"ax.set_xticklabels(ax.xaxis.get_majorticklabels(), rotation=45)"
|
create dataframe `df` with content of hdf store file '/home/.../data.h5' with key of 'firstset',"df1 = pd.read_hdf('/home/.../data.h5', 'firstSet')"
|
count the number of values in `d` dictionary that are predicate to function `some_condition`,sum(1 for x in list(d.values()) if some_condition(x))
|
django jinja slice list `mylist` by '3:8',{{(mylist | slice): '3:8'}}
|
convert string to dict using list comprehension in python,"dict((n, int(v)) for n, v in (a.split('=') for a in string.split()))"
|
python split string with multiple-character delimiter,"""""""Hello there. My name is Fr.ed. I am 25.5 years old."""""".split('. ')"
|
make a 60 seconds time delay,time.sleep(60)
|
python: extract numbers from a string,"re.findall('\\d+', ""hello 42 I'm a 32 string 30"")"
|
set dataframe `df` index using column 'month',df.set_index('month')
|
how to set the tab order in a tkinter application?,app.mainloop()
|
extracting words between delimiters [] in python,"print(re.findall('\\[([^]]*)\\]', s))"
|
sum up column values in pandas dataframe,"df.groupby(['score', 'type']).sum()"
|
how do i read a text file into a string variable in python,"str = open('very_Important.txt', 'r').read()"
|
calling a parent class constructor from a child class in python,"super(Instructor, self).__init__(name, year)"
|
get equivalent week number from a date `2010/6/16` using isocalendar,"datetime.date(2010, 6, 16).isocalendar()[1]"
|
convert 21 to binary string,bin(21)
|
python3 datetime.datetime.strftime failed to accept utf-8 string format,strftime('%Y{0}%m{1}%d{2}').format(*'\xe5\xb9\xb4\xe6\x9c\x88\xe6\x97\xa5')
|
select children of an object with foreignkey in django?,blog.comment_set.all()
|
flush output of python print,sys.stdout.flush()
|
get a string with string formatting from dictionary `d`,""""""", """""".join(['{}_{}'.format(k, v) for k, v in d.items()])"
|
get multiple integer values from a string 'string1',"map(int, re.findall('\\d+', string1))"
|
"python: is there a way to plot a ""partial"" surface plot with matplotlib?",plt.show()
|
passing an argument to a python script and opening a file,name = sys.argv[1:]
|
slicing url with python,url.split('&')
|
how to add items into a numpy array,"array([[1, 3, 4, 10], [1, 2, 3, 20], [1, 2, 1, 30]])"
|
how can i get the output of a matplotlib plot as an svg?,"plt.gca().set_position([0, 0, 1, 1])"
|
connecting a slot to a button in qdialogbuttonbox,self.buttonBox.button(QtGui.QDialogButtonBox.Reset).clicked.connect(foo)
|
sort list `lst` with positives coming before negatives with values sorted respectively,"sorted(lst, key=lambda x: (x < 0, x))"
|
lisp cons in python,self.cdr = cdr
|
token pattern for n-gram in tfidfvectorizer in python,"re.findall('(?u)\\b\\w\\w+\\b', 'this is a sentence! this is another one.')"
|
how can i sum the product of two list items using for loop in python?,"list(x * y for x, y in list(zip(a, b)))"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.