text stringlengths 4 1.08k |
|---|
python selenium: find object attributes using xpath,"browser.find_elements_by_xpath(""//*[@type='submit']"").get_attribute('value')" |
list of integers into string (byte array) - python,"str(bytearray([17, 24, 121, 1, 12, 222, 34, 76]))" |
first non-null value per row from a list of pandas columns,df.stack().groupby(level=0).first().reindex(df.index) |
python image library produces a crappy quality jpeg when i resize a picture,"im.save(thumbnail_file, 'JPEG', quality=90)" |
create 2d array in python using for loop results,"[[0, 0], [1, 10], [2, 20], [3, 30], [4, 40], [5, 50]]" |
authenticate with private key using paramiko transport (channel),session.exec_command('cd /home/harperville/my_scripts/') |
sort by key of dictionary inside a dictionary in python,"result = sorted(iter(promotion_items.items()), key=lambda pair: list(pair[1].items()))" |
how to update djangoitem in scrapy,ITEM_PIPELINES = {'apps.scrapy.pipelines.ItemPersistencePipeline': 999} |
simple way to toggle fullscreen with f11 in pygtk,"window.connect('key-press-event', fullscreen_toggler)" |
how to check if one of the following items is in a list?,print(any(x in a for x in b)) |
determine if python variable is an instance of a built-in type,type(theobject).__name__ in dir(__builtins__) |
how to find out if the elements in one list are in another?,print([x for x in A if all(y in x for y in B)]) |
how would one add a colorbar to this example?,plt.show() |
how can i resize the root window in tkinter?,root.geometry('500x500') |
is there any elegant way to build a multi-level dictionary in python?,"print(multidict(['a', 'b'], ['A', 'B'], ['1', '2'], {}))" |
how to select parent based on the child in lxml?,"t.xpath('//a[@href = ""http://exact url""]')[0]" |
drawing a huge graph with networkx and matplotlib,"plt.savefig('graph.png', dpi=1000)" |
sum of all values in a python dict,sum(d.values()) |
randomly switch letters' cases in string `s`,""""""""""""".join(x.upper() if random.randint(0, 1) else x for x in s)" |
how to select a radio button?,"br.form.set_value(['1'], name='prodclass')" |
changing the process name of a python script,procname.setprocname('My super name') |
working with nested lists in python,result = (list_[0][0] + list_[1][0]) * (list_[0][1] + list_[1][1]) |
delete digits in python (regex),"s = re.sub('^\\d+\\s|\\s\\d+\\s|\\s\\d+$', ' ', s)" |
adding odd numbers in a list,print(sum(num for num in numbers if num % 2 == 1)) |
find the sums of length 7 subsets of a list `daily`,"weekly = [sum(visitors[x:x + 7]) for x in range(0, len(daily), 7)]" |
converting currency with $ to numbers in python pandas,"df[df.columns[1:]].replace('[\\$,]', '', regex=True).astype(float)" |
create a default empty json object if no json is available in request parameter `mydata`,"json.loads(request.POST.get('mydata', '{}'))" |
how do i grab the last portion of a log string and interpret it as json?,"""""""a b c d my json expression"""""".split(maxsplit=4)" |
python pandas: how to move one row to the first row of a dataframe?,df.sort(inplace=True) |
python : how to append new elements in a list of list?,"[[], [], []]" |
how can i show figures separately in matplotlib?,plt.show() |
get the number of values in list `j` that is greater than 5,sum(((i > 5) for i in j)) |
get current ram usage of current program,"pid = os.getpid() |
py = psutil.Process(pid) |
memoryUse = (py.memory_info()[0] / (2.0 ** 30))" |
can i put a breakpoint in a running python program that drops to the interactive terminal?,pdb.set_trace() |
"how to print a list with integers without the brackets, commas and no quotes?","print(int(''.join(str(x) for x in [7, 7, 7, 7])))" |
close a tkinter window?,root.mainloop() |
"how to do a left,right and mid of a string in a pandas dataframe",df['state'].apply(lambda x: x[len(x) / 2 - 1:len(x) / 2 + 1]) |
"delete mulitple columns `columnheading1`, `columnheading2` in pandas data frame `yourdf`","yourdf.drop(['columnheading1', 'columnheading2'], axis=1, inplace=True)" |
write a string `my string` to a file `file` including new line character,file.write('My String\n') |
"sort list of names in python, ignoring numbers?","sorted(l, key=lambda s: (s.isdigit(), s))" |
how do you create line segments between two points?,plt.show() |
calcuate mean for selected rows for selected columns in pandas data frame,"df.iloc[[1, 2, 3, 4], [2, 5, 6, 7, 8]]" |
sort a nested list by two elements,"sorted(l, key=lambda x: (-int(x[1]), x[0]))" |
python 3 script to upload a file to a rest url (multipart request),"r = requests.post(url, files=files)" |
get unique values from a list in python,"set(['a', 'b', 'c', 'd'])" |
summing across rows of pandas dataframe,df2.reset_index() |
scrapy: convert html string to htmlresponse object,"response.xpath('//div[@id=""test""]/text()').extract()[0].strip()" |
remove elements from an array `a` that are in array `b`,"A[np.all(np.any(A - B[:, (None)], axis=2), axis=0)]" |
get the next value greatest to `2` from a list of numbers `num_list`,min([x for x in num_list if x > 2]) |
how can i control a fan with gpio on a raspberry pi 3 using python?,time.sleep(5) |
how to use schemas in django?,"db_table = 'schema"".""tablename'" |
what does a colon and comma stand in a python list?,"foo[:, (1)]" |
convert binary to list of digits python,[int(d) for d in str(bin(x))[2:]] |
how can i capture the stdout output of a child process?,sys.stdout.flush() |
how can i strip the file extension from a list full of filenames?,lst.append(os.path.splitext(x)[0]) |
remove attribute from all mongodb documents using python and pymongo,"mongo.db.collection.update({}, {'$unset': {'parent.toremove': 1}}, multi=True)" |
convert a unicode string `a` to a 'ascii' string,"a.encode('ascii', 'ignore')" |
substitute multiple whitespace with single whitespace in python,""""""" """""".join(mystring.split())" |
test if lists share any items in python,any(i in a for i in b) |
how to achieve two separate list of lists from a single list of lists of tuple with list comprehension?,"[y for sublist in l for x, y in sublist]" |
creating an empty list `l`,l = list() |
send xml file to http using python,print(response.read()) |
how to close urllib2 connection?,connection.close() |
picking out items from a python list which have specific indexes,"[e for i, e in enumerate(main_list) if i in indexes]" |
python: how to check a string for substrings from a list?,any(substring in string for substring in substring_list) |
python - getting list of numbers n to 0,"range(N, -1, -1)" |
receiving broadcast packets in python,"s.bind(('', 12345))" |
how to use python to calculate time,"print(now + datetime.timedelta(hours=1, minutes=23, seconds=10))" |
how to set my xlabel at the end of xaxis,plt.show() |
decode complex json in python,json.loads(s) |
is there a way to make the tkinter text widget read only?,text.config(state=DISABLED) |
encode a pdf file `pdf_reference.pdf` with `base64` encoding,"a = open('pdf_reference.pdf', 'rb').read().encode('base64')" |
how to write a tuple of tuples to a csv file using python,writer.writerow(A) |
how to disable formatting for floatfield in template for django,{{value | safe}} |
regex for removing data in parenthesis,"print(re.sub(' \\(\\w+\\)', '', item))" |
mitm proxy over ssl hangs on wrap_socket with client,connection.send('HTTP/1.0 200 established\r\n\r\n') |
how to store indices in a list,"['ABC', 'F']" |
working with set_index in pandas dataframe,"rdata.set_index(['race_date', 'track_code', 'race_number'])" |
python & matplotlib: creating two subplots with different sizes,plt.show() |
how can i get affected row count from psycopg2 connection.commit()?,_cxn.commit() |
how to split long regular expression rules to multiple lines in python,re.compile('[A-Za-z_][A-Za-z0-9_]*') |
get the address of a ctypes object,ctypes.addressof(bufstr) |
nonlinear colormap with matplotlib,plt.show() |
how do i fill a region with only hatch (no background colour) in matplotlib 2.0,plt.show() |
pandas dataframe - desired index has duplicate values,"df.pivot('Symbol', 'TimeStamp').stack()" |
customize x-axis in matplotlib,ax.set_xlabel('Hours') |
python: invalid literal for int() with base 10: '808.666666666667',int(float('808.666666666667')) |
how to blend drawn circles with pygame,pygame.display.flip() |
how to profile my code?,"cProfile.runctx('Your code here', globals(), locals(), 'output_file')" |
how to get column by number in pandas?,df['b'] |
how to group by date range,"df.groupby(['employer_key', 'account_id'])" |
python unicode in mac os x terminal,print('\xd0\xb0\xd0\xb1\xd0\xb2\xd0\xb3\xd0\xb4') |
a sequence of empty lists of length `n`,[[] for _ in range(n)] |
python: split list of strings to a list of lists of strings by length with a nested comprehensions,"[['a', 'b'], ['ab'], ['abc']]" |
get day name from a datetime object,date.today().strftime('%A') |
how do i get the index of the largest list inside a list of lists using python?,"max(enumerate(props), key=lambda tup: len(tup[1]))" |
how to unpack multiple tuples in function call,"f(tup1[0], tup1[1], tup2[0], tup2[1])" |
print line `line` from text file with 'utf-16-le' format,print(line.decode('utf-16-le').split()) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.