text
stringlengths
4
1.08k
How to modify css by class name in selenium,"driver.execute_script(""arguments[0].style.border = '1px solid red';"")"
How to count number of rows in a group in pandas group by object?,"df[['col1', 'col2', 'col3', 'col4']]"
How to count the number of occurences of `None` in a list?,print(len([x for x in lst if x is not None]))
Convert a list to a dictionary in Python,"b = {a[i]: a[i + 1] for i in range(0, len(a), 2)}"
test a boolean expression in a Python string,eval('20<30')
How to create a list with the characters of a string?,list('5+6')
Django can't find URL pattern,"url('^', include('sms.urls')),"
Django can't find URL pattern,"url('^$', include('sms.urls')),"
get key by value in dictionary with same value in python?,"print([key for key, value in list(d.items()) if value == 1])"
Check if string contains a certain amount of words of another string,"re.findall('(?=(\\w+\\s+\\w+))', 'B D E')"
How to sort a LARGE dictionary,"['002', '020', 'key', 'value']"
How to find duplicate elements in array using for loop in Python?,[i for i in y if y[i] == 1]
How to perform double sort inside an array?,"bar.sort(key=lambda x: (x.attrb1, x.attrb2), reverse=True)"
Converting html to text with Python,print(soup.get_text())
Extracting only characters from a string in Python,""""""" """""".join(re.split('[^a-zA-Z]*', 'your string'))"
Can I extend within a list of lists in python?,"[[1, 100313, 0, 0, 1], [2, 100313, 0, 0, 1], [1, 100314, 0, 1, 0], [3, 100315]]"
How do I un-escape a backslash-escaped string in python?,"print('""Hello,\\nworld!""'.decode('string_escape'))"
Python regular expression for Beautiful Soup,"soup.find_all('div', class_=re.compile('comment-'))"
Confusing with the usage of regex in Python,"re.findall('([a-z])*', 'f233op')"
Confusing with the usage of regex in Python,"re.findall('([a-z]*)', 'f233op')"
How to get all children of queryset in django?,Animals.objects.filter(name__startswith='A')
Python [Errno 98] Address already in use,"sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)"
How can I handle an alert with GhostDriver via Python?,driver.execute_script('return lastAlert')
How do I merge two lists into a single list?,"[j for i in zip(a, b) for j in i]"
Creating a pandas DataFrame from columns of other DataFrames with similar indexes,"pd.concat([df1['c'], df2['c']], axis=1, keys=['df1', 'df2'])"
Combining rows in pandas,df.groupby(df.index).sum()
Regular expression in Python sentence extractor,"re.split('\\.\\s', text)"
Replace a string in list of lists,"example = [x.replace('\r\n', '') for x in example]"
Python Accessing Values in A List of Dictionaries,"[(d['Name'], d['Age']) for d in thisismylist]"
Reverse Y-Axis in PyPlot,plt.gca().invert_xaxis()
Django - How to sort queryset by number of character in a field,MyModel.objects.extra(select={'length': 'Length(name)'}).order_by('length')
Python: Converting from binary to String,"struct.pack('<I', 1633837924)"
Pandas group by time windows,s.groupby(grouper).sum()
How to sort pandas data frame using values from several columns?,"df.sort(['c1', 'c2'], ascending=[True, True])"
Splitting a string by list of indices,"['long ', 'string ', 'that ', 'I want to split up']"
Django database query: How to filter objects by date range?,"Sample.objects.filter(date__range=['2011-01-01', '2011-01-31'])"
How to use Unicode characters in a python string,print('\u25b2'.encode('utf-8'))
How to get one number specific times in an array python,"[4, 5, 5, 6, 6, 6]"
How to set environment variables in Python,os.environ['DEBUSSY'] = '1'
Get current URL in Python,self.request.url
How do convert a pandas/dataframe to XML?,print(df.to_xml())
Python: how to suppress logging statements from third party libraries?,logging.basicConfig()
Converting a dict into a list,[y for x in list(dict.items()) for y in x]
Python how to sort this list?,"sorted(lst, reverse=True)"
How can I remove all instances of an element from a list in Python?,"[x for x in a if x != [1, 1]]"
How to filter model results for multiple values for a many to many field in django,"Group.objects.filter(player__name__in=['Player1', 'Player2'])"
Python: How to get attribute of attribute of an object with getattr?,"getattr(getattr(myobject, 'id', None), 'number', None)"
How do I modify the width of a TextCtrl in wxPython?,"wx.TextCtrl(self, -1, size=(300, -1))"
Get SQL headers from Numpy Array in python,"[('a', '<i4'), ('b', '<i4'), ('c', '<i4')]"
Get SQL headers from Numpy Array in python,"[('a', '|O4'), ('b', '|O4'), ('c', '|O4')]"
How can I print the Truth value of a variable?,print(bool(a))
Python: use regular expression to remove the white space from all lines,"re.sub('(?m)^\\s+', '', 'a\n b\n c')"
Pythonic way to insert every 2 elements in a string,"""""""-"""""".join(a + b for a, b in zip(s[::2], s[1::2]))"
How to get n elements of a list not contained in another one?,"set([3, 5, 7, 9])"
How to properly determine current script directory in Python?,os.path.dirname(os.path.abspath(__file__))
Django - How to simply get domain name?,request.META['HTTP_HOST']
How to strip all whitespace from string,"s.replace(' ', '')"
Matching 2 regular expressions in Python,"re.match('^(a+)+$', 'a' * 24 + '!')"
Capturing emoticons using regular expression in python,"re.match('[:;][)(](?![)(])', str)"
Sorting a list of lists by length and by value,"sorted(a, key=lambda x: (len(x), [confrom[card[0]] for card in x]))"
Pandas sort row values,"df.sort_values(by=1, ascending=False, axis=1)"
Create variable key/value pairs with argparse (python),"parser.add_argument('--conf', nargs=2, action='append')"
What is the easiest way to convert list with str into list with int?,"list(map(int, ['1', '2', '3']))"
Multiple positional arguments with Python and argparse,"parser.add_argument('input', nargs='+')"
How to get column by number in Pandas?,df['b']
How to get the n next values of a generator in a list (python),"list(itertools.islice(it, 0, n, 1))"
How to add multiple values to a dictionary key in python?,"a.setdefault('somekey', []).append('bob')"
"python, subprocess: reading output from subprocess",sys.stdout.flush()
Creating a JSON response using Django and Python,"return HttpResponse(json.dumps(response_data), content_type='application/json')"
Regex. Match words that contain special characters or 'http://',"re.sub('(http://\\S+|\\S*[^\\w\\s]\\S*)', '', a)"
How to create a density plot in matplotlib?,plt.show()
How to get the indices list of all NaN value in numpy array?,"array([[1, 2], [2, 0]])"
Access an arbitrary element in a dictionary in Python,next(iter(list(dict.values())))
How to get integer values from a string in Python?,"map(int, re.findall('\\d+', string1))"
Python Accessing Values in A List of Dictionaries,[d['Name'] for d in thisismylist]
ValueError: setting an array element with a sequence,"numpy.array([[1, 2], [2, 3, 4]])"
From a list of lists to a dictionary,{x[1]: x for x in lol}
Is there a way to make multiple horizontal boxplots in matplotlib?,plt.show()
How can I remove all instances of an element from a list in Python?,"a[:] = [x for x in a if x != [1, 1]]"
sorting list of tuples by arbitrary key,"sorted(mylist, key=lambda x: order.index(x[1]))"
Python: Filter lines from a text file which contain a particular word,[line for line in open('textfile') if 'apple' in line]
UTF in Python Regex,re.compile('\xe2\x80\x93')
How to shift a string to right in python?,""""""" """""".join(l[-1:] + l[:-1])"
Image foveation in Python,cv2.destroyAllWindows()
Python - convert string to list,"['Alaska Alabama Arkansas American Samoa ', 'zona California Colorado']"
python pandas dataframe to dictionary,df.set_index('id')['value'].to_dict()
Get a string after a specific substring,"print(my_string.split(', ', 1)[1])"
"Regular expression syntax for ""match nothing""?",re.compile('a^')
How to create a list with the characters of a string?,"['5', '+', '6']"
How can I get pyplot images to show on a console app?,matplotlib.pyplot.show()
How to derive the week start for a given (iso) weeknumber / year in python,"datetime.datetime.strptime('2011, 4, 0', '%Y, %U, %w')"
Python: Write a list of tuples to a file,"open('filename', 'w').write('\n'.join('%s %s' % x for x in mylist))"
Parsing HTML page using beautifulsoup,print(''.join([str(t).strip() for t in x.findAll(text=True)]))
sum of squares in a list in one line?,"sum(map(lambda x: x * x, l))"
How to filter by sub-level index in Pandas,df[df.index.map(lambda x: x[1].endswith('0630'))]
How to find all possible sequences of elements in a list?,"map(list, permutations([2, 3, 4]))"
How can I insert NULL data into MySQL database with Python?,"cursor.execute('INSERT INTO table (`column1`) VALUES (%s)', (value,))"
Python getting a string (key + value) from Python Dictionary,""""""", """""".join(['{}_{}'.format(k, v) for k, v in d.items()])"
Convert DataFrame column type from string to datetime,df['col'] = pd.to_datetime(df['col'])
Sorting a list of tuples by the addition of second and third element of the tuple,"sorted(lst, key=lambda x: (sum(x[1:]), x[0]), reverse=True)"