In-place edits with sed on OS X

You can use the -i flag correctly by providing it with a suffix to add to the backed-up file. Extending your example: sed -i.bu ‘s/oldword/newword/’ file1.txt Will give you two files: one with the name file1.txt that contains the substitution, and one with the name file1.txt.bu that has the original content. Mildly dangerous If you … Read more

What is the difference between `sorted(list)` vs `list.sort()`?

sorted() returns a new sorted list, leaving the original list unaffected. list.sort() sorts the list in-place, mutating the list indices, and returns None (like all in-place operations). sorted() works on any iterable, not just lists. Strings, tuples, dictionaries (you’ll get the keys), generators, etc., returning a list containing all elements, sorted. Use list.sort() when you … Read more

Understanding inplace=True in pandas

When inplace=True is passed, the data is renamed in place (it returns nothing), so you’d use: df.an_operation(inplace=True) When inplace=False is passed (this is the default value, so isn’t necessary), performs the operation and returns a copy of the object, so you’d use: df = df.an_operation(inplace=False)