text
stringlengths 4
1.08k
|
|---|
Python 2.7 Counting number of dictionary items with given value,sum(1 for x in list(d.values()) if some_condition(x))
|
How to iterate over Unicode characters in Python 3?,print('U+{:04X}'.format(ord(c)))
|
split a string in python,a.rstrip().split('\n')
|
python regex: match a string with only one instance of a character,"re.match('\\$[0-9]+[^\\$]*$', '$1 off delicious $5 ham.')"
|
"python: convert ""5,4,2,4,1,0"" into [[5, 4], [2, 4], [1, 0]]","[[5, 4], [2, 4], [1, 0], [3, 0], [5, 1], [3, 3], [4, 3], [3, 5]]"
|
Django class-based view: How do I pass additional parameters to the as_view method?,"url('^(?P<slug>[a-zA-Z0-9-]+)/$', MyView.as_view(), name='my_named_view')"
|
Python: How to use a list comprehension here?,[y['baz'] for x in foos for y in x['bar']]
|
Python Pandas - How to flatten a hierarchical index in columns,df.columns = [' '.join(col).strip() for col in df.columns.values]
|
python list comprehension with multiple 'if's,[i for i in range(100) if i > 10 if i < 20]
|
Replace Substring in a List of String,"['hanks sir', 'Oh thanks to remember']"
|
How can I stop raising event in Tkinter?,root.mainloop()
|
Dictionaries are ordered in CPython 3.6,"d = {'timmy': 'red', 'barry': 'green', 'guido': 'blue'}"
|
How to use bower package manager in Django App?,{'directory': 'app/static/bower_components'}
|
How to get a file close event in python,app.exec_()
|
how do I sort a python list of dictionaries given a list of ids with the desired order?,users.sort(key=lambda x: order.index(x['id']))
|
How to get different colored lines for different plots in a single figure?,plt.show()
|
Redirect print to string list?,"['i = ', ' ', '0', '\n', 'i = ', ' ', '1', '\n']"
|
Python - regex - special characters and ñ,"w = re.findall('[a-zA-Z\xd1\xf1]+', p.decode('utf-8'))"
|
Getting the first item item in a many-to-many relation in Django,Group.objects.get(id=1).members.all()[0]
|
How to make matrices in Python?,print('\n'.join([' '.join(row) for row in matrix]))
|
Finding the surrounding sentence of a char/word in a string,"re.split('(?<=\\?|!|\\.)\\s{0,2}(?=[A-Z]|$)', text)"
|
Finding missing values in a numpy array,m[~m.mask]
|
Using savepoints in python sqlite3,"conn.execute('insert into example values (?, ?);', (5, 205))"
|
How to define two-dimensional array in python,matrix = [([0] * 5) for i in range(5)]
|
Dirty fields in django,"super(Klass, self).save(*args, **kwargs)"
|
Convert Django Model object to dict with all of the fields intact,"{'id': 1, 'reference1': 1, 'reference2': [1], 'value': 1}"
|
How do I convert an int representing a UTF-8 character into a Unicode code point?,return s.decode('hex').decode('utf-8')
|
filtering elements from list of lists in Python?,[item for item in a if sum(item) > 10]
|
"How do I iterate over a Python dictionary, ordered by values?","sorted(list(dictionary.items()), key=operator.itemgetter(1))"
|
How can I get the index value of a list comprehension?,"{(p.id, ind): {'id': p.id, 'position': ind} for ind, p in enumerate(p_list)}"
|
How to resample a df with datetime index to exactly n equally sized periods?,"df.resample('3D', how='sum')"
|
How to resample a df with datetime index to exactly n equally sized periods?,"df.resample('216000S', how='sum')"
|
Is it possible to add a where clause with list comprehension?,"[(x, f(x)) for x in iterable if f(x)]"
|
Selecting specific rows and columns from NumPy array,"a[[[0], [1], [3]], [0, 2]]"
|
Is there a way to know if a list of elements is on a larger list without using 'in' keyword?,"print(in_list([1, 2, 3], [1, 2, 4]))"
|
How to create a comprehensible bar chart with matplotlib for more than 100 values?,"plt.savefig('foo.pdf', papertype='a2')"
|
How to remove parentheses and all data within using Pandas/Python?,"df['name'].str.replace('\\(.*\\)', '')"
|
get count of values associated with key in dict python,sum(1 if d['success'] else 0 for d in s)
|
How would I check a string for a certain letter in Python?,"'x' in ['x', 'd', 'a', 's', 'd', 's']"
|
Using SCSS with Flask,app.run(debug=True)
|
Python - How to calculate equal parts of two dictionaries?,"d3 = {k: list(set(d1.get(k, [])).intersection(v)) for k, v in list(d2.items())}"
|
Looking for a simple OpenGL (3.2+) Python example that uses GLFW,glfw.Terminate()
|
How to remove whitespace in BeautifulSoup,"re.sub('[\\ \\n]{2,}', '', yourstring)"
|
How to get current date and time from DB using SQLAlchemy,"print(select([my_table, func.current_date()]).execute())"
|
Seaborn Plot including different distributions of the same data,"sns.pointplot(x='grp', y='val', hue='grp', data=df)"
|
Sorting one list to match another in python,"sorted(objects, key=lambda x: idmap[x['id']])"
|
Python - find digits in a string,""""""""""""".join(c for c in my_string if c.isdigit())"
|
Select all text in a textbox Selenium RC using Ctrl + A,element.click()
|
How can I produce student-style graphs using matplotlib?,plt.show()
|
How to use 'User' as foreign key in Django 1.5,"user = models.ForeignKey('User', unique=True)"
|
Python convert tuple to string,""""""""""""".join(('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e'))"
|
Split string into strings of repeating elements,"print([a for a, b in re.findall('((\\w)\\2*)', s)])"
|
Cleanest way to get a value from a list element,"print(re.search('\\bLOG_ADDR\\s+(\\S+)', line).group(1))"
|
Is there a way to get a list of column names in sqlite?,"names = list(map(lambda x: x[0], cursor.description))"
|
Selenium Webdriver - NoSuchElementExceptions,driver.switch_to_frame('frameName')
|
How to print a list more nicely?,"zip([1, 2, 3], ['a', 'b', 'c'], ['x', 'y', 'z'])"
|
Python : how to append new elements in a list of list?,"[1, 2, 3, 4]"
|
"In python, how to get subparsers to read in parent parser's argument?",args = parser.parse_args()
|
How to execute process in Python where data is written to stdin?,process.stdin.close()
|
Add x and y labels to a pandas plot,ax.set_ylabel('y label')
|
How to retrieve executed SQL code from SQLAlchemy,session.commit()
|
Slicing numpy array with another array,"a = np.concatenate((a, [0]))"
|
How to implement server push in Flask framework?,app.run(threaded=True)
|
Reading GPS RINEX data with Pandas,"df.set_index(['%_GPST', 'satID'])"
|
Extract first and last row of a dataframe in pandas,"pd.concat([df.head(1), df.tail(1)])"
|
how to export a table dataframe in pyspark to csv?,df.write.csv('mycsv.csv')
|
How to use HTTP method DELETE on Google App Engine?,self.response.out.write('Permission denied')
|
write to csv from DataFrame python pandas,"a.to_csv('test.csv', cols=['sum'])"
|
Regex Python adding characters after a certain word,"text = re.sub('(\\bget\\b)', '\\1@', text)"
|
Using SCSS with Flask,app.debug = True
|
Setting up a LearningRateScheduler in Keras,model.predict(X_test)
|
How to get value from form field in django framework?,"return render_to_response('contact.html', {'form': form})"
|
python -> time a while loop has been running,time.sleep(1)
|
Pyhon - Best way to find the 1d center of mass in a binary numpy array,np.flatnonzero(x).mean()
|
How to group pandas DataFrame entries by date in a non-unique column,data.groupby(data['date'].map(lambda x: x.year))
|
How do I specify a range of unicode characters,"re.compile('[ -\xd7ff]', re.DEBUG)"
|
How do I specify a range of unicode characters,"re.compile('[ -\ud7ff]', re.DEBUG)"
|
How can I indirectly call a macro in a Jinja2 template?,print(template.render())
|
Print LIST of unicode chars without escape characters,"print('[' + ','.join(""'"" + str(x) + ""'"" for x in s) + ']')"
|
String manipulation in Cython,"re.sub(' +', ' ', s)"
|
How to extract first two characters from string using regex,"df.c_contofficeID.str.replace('^12(?=.{4}$)', '')"
|
Python: Find in list,"3 in [1, 2, 3]"
|
"How to join two sets in one line without using ""|""","set([1, 2, 3]) | set([4, 5, 6])"
|
How to access pandas groupby dataframe by key,"df.loc[gb.groups['foo'], ('A', 'B')]"
|
How to convert a Numpy 2D array with object dtype to a regular 2D array of floats,"np.array(list(arr[:, (1)]), dtype=np.float)"
|
remove italics in latex subscript in matplotlib,plt.xlabel('Primary T$_{\\rm eff}$')
|
Split Strings with Multiple Delimiters?,"""""""a;bcd,ef g"""""".replace(';', ' ').replace(',', ' ').split()"
|
How to sort a dataFrame in python pandas by two or more columns?,"df.sort_values(['b', 'c'], ascending=[True, False], inplace=True)"
|
How can I detect DOS line breaks in a file?,"print(open('myfile.txt', 'U').read())"
|
Python PIL: how to write PNG image to string,"image.save(output, format='GIF')"
|
What is the best way to capture output from a process using python?,"process = subprocess.Popen(['python', '-h'], bufsize=1)"
|
How to gracefully fallback to `NaN` value while reading integers from a CSV with Pandas?,"df = pd.read_csv('my.csv', dtype={'my_column': np.float64}, na_values=['n/a'])"
|
Read lines containing integers from a file in Python?,line.strip().split(' ')
|
How can I add the corresponding elements of several lists of numbers?,"map(sum, zip(*lists))"
|
How to create a sequential combined list in python?,"[''.join(['a', 'b', 'c', 'd'])[i:j + 1] for i in range(4) for j in range(i, 4)]"
|
Image library for Python 3,img.save('output.png')
|
Get name of primary field of Django model,CustomPK._meta.pk.name
|
How to get the n next values of a generator in a list (python),[next(it) for _ in range(n)]
|
Most efficient method to get key for similar values in a dict,"trie = {'a': {'b': {'e': {}, 's': {}}, 'c': {'t': {}, 'k': {}}}}"
|
How to include third party Python libraries in Google App Engine?,"sys.path.insert(0, 'libs')"
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.