text
stringlengths 4
1.08k
|
---|
How to replace only part of the match with python re.sub,"re.sub('(\\_a)?\\.([^\\.]*)$', '_suff.\\2', 'long.file.name.jpg')" |
How can I reload objects in my namespace in ipython,"import imp |
imp.reload(module)" |
How to get a 16bit Unsigned integer in python,"struct.unpack('H', struct.pack('h', number))" |
How can I use sum() function for a list in Python?,numlist = [float(x) for x in numlist] |
Removing index column in pandas,"df.to_csv(filename, index=False)" |
How to convert a string data to a JSON object in python?,json_data = json.loads(unescaped) |
Is there a Python Library that contains a list of all the ascii characters?,[chr(i) for i in range(127)] |
Python how to write to a binary file?,"newFile.write(struct.pack('5B', *newFileBytes))" |
Python Regex - checking for a capital letter with a lowercase after,"re.sub('^[A-Z0-9]*(?![a-z])', '', string)" |
Last Key in Python Dictionary,list(dict.keys())[-1] |
write line to file,"print('hi there', file=f)" |
write line to file,"f = open('myfile', 'w') |
f.write('hi there\n')" |
write line to file,"with open('somefile.txt', 'a') as the_file: |
the_file.write('Hello\n')" |
Python - Unicode to ASCII conversion,s.encode('iso-8859-15') |
How to get max value in django ORM,AuthorizedEmail.objects.filter(group=group).order_by('-added')[0] |
Python regex findall numbers and dots,"re.findall('Test([0-9.]*[0-9]+)', text)" |
Python regex findall numbers and dots,"re.findall('Test([\\d.]*\\d+)', text)" |
Is there a way to run powershell code in python,"os.system('powershell.exe', 'script.ps1')" |
Sorting a dictionary of tuples in Python,b.sort(key=lambda x: x[1][2]) |
How do I get all the keys that are stored in the Cassandra column family with pycassa?,list(cf.get_range().get_keys()) |
how to create a file name with the current date & time in python?,datetime.datetime.now() |
How to get the index of an integer from a list if the list contains a boolean?,"next(i for i, x in enumerate(lst) if not isinstance(x, bool) and x == 1)" |
Subtract a value from every number in a list in Python?,a[:] = [(x - 13) for x in a] |
Best way to choose a random file from a directory,random.choice(os.listdir('C:\\')) |
How to get the highest element in absolute value in a numpy matrix?,"max(x.min(), x.max(), key=abs)" |
Using Regular Expressions to extract specific urls in python,"re.findall('""(http.*?)""', s, re.MULTILINE | re.DOTALL)" |
Using Regular Expressions to extract specific urls in python,"re.findall('http://[^t][^s""]+\\.html', document)" |
Is there a function in Python to split a string without ignoring the spaces?,"mystring.replace(' ', '! !').split('!')" |
Open file in Python,"open(path, 'r')" |
Sum of multiple list of lists index wise,[[sum(item) for item in zip(*items)] for items in zip(*data)] |
"numpy: syntax/idiom to cast (n,) array to a (n, 1) array?","a[:, (np.newaxis)]" |