Questions tagged [in-place]

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place sorting, in-place merge, etc.

Use this tag on questions about algorithms that modify the data in-place, as opposed to making a copy. For example, in-place , in-place , etc.

379 questions
2301
votes
21 answers

How to delete from a text file, all lines that contain a specific string?

How would I use sed to delete all lines in a text file that contain a specific string?
A Clockwork Orange
  • 23,913
  • 7
  • 25
  • 28
295
votes
10 answers

How to sort in-place using the merge sort algorithm?

I know the question is not too specific. All I want is someone to tell me how to convert a normal merge sort into an in-place merge sort (or a merge sort with constant extra space overhead). All I can find (on the net) is pages saying "it is too…
Lazer
  • 90,700
  • 113
  • 281
  • 364
295
votes
19 answers

How can I convert tabs to spaces in every file of a directory?

How can I convert tabs to spaces in every file of a directory (possibly recursively)? Also, is there a way of setting the number of spaces per tab?
cnd
  • 32,616
  • 62
  • 183
  • 313
291
votes
7 answers

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

list.sort() sorts the list and replaces the original list, whereas sorted(list) returns a sorted copy of the list, without changing the original list. When is one preferred over the other? Which is more efficient? By how much? Can a list be…
alvas
  • 115,346
  • 109
  • 446
  • 738
252
votes
8 answers

In-place edits with sed on OS X

I'd like edit a file with sed on OS X. I'm using the following command: sed 's/oldword/newword/' file.txt The output is sent to the terminal. file.txt is not modified. The changes are saved to file2.txt with this command: sed…
SundayMonday
  • 19,147
  • 29
  • 100
  • 154
211
votes
15 answers

In-Place Radix Sort

This is a long text. Please bear with me. Boiled down, the question is: Is there a workable in-place radix sort algorithm? Preliminary I've got a huge number of small fixed-length strings that only use the letters “A”, “C”, “G” and “T” (yes, you've…
Konrad Rudolph
  • 530,221
  • 131
  • 937
  • 1,214
169
votes
11 answers

Understanding inplace=True in pandas

In the pandas library many times there is an option to change the object inplace such as with the following statement... df.dropna(axis='index', how='all', inplace=True) I am curious what is being returned as well as how the object is handled when…
Aran Freel
  • 3,085
  • 5
  • 29
  • 42
143
votes
11 answers

jq to replace text directly on file (like sed -i)

I have a json file that needs to be updated on a certain condition. Sample json { "Actions" : [ { "value" : "1", "properties" : { "name" : "abc", "age" : "2", "other ": "test1" …
Supra
  • 1,453
  • 2
  • 10
  • 6
138
votes
4 answers

Pandas: drop columns with all NaN's

I have this DataFrame: 0 1 2 3 4 5 6 7 0 #0915-8 NaN NaN NaN NaN NaN NaN NaN 1 NaN NaN NaN LIVE WGT NaN AMOUNT NaN TOTAL 2 GBW…
theprowler
  • 3,138
  • 11
  • 28
  • 39
91
votes
3 answers

Difference between a -= b and a = a - b in Python

I have recently applied this solution for averaging every N rows of matrix. Although the solution works in general I had problems when applied to a 7x1 array. I have noticed that the problem is when using the -= operator. To make a small…
iasonas
  • 895
  • 7
  • 12
84
votes
4 answers

Python Math - TypeError: 'NoneType' object is not subscriptable

I'm making a small program for math (no particular reason, just kind of wanted to) and I ran into the error "TypeError: 'NoneType' object is not subscriptable. I have never before seen this error, so I have no idea what it means. import…
Fen
  • 892
  • 1
  • 6
  • 8
78
votes
3 answers

Updating a java map entry

I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map, and I want to update the value in a Key-Value pair. Right now, I'm doing it lik this: private Map table = new HashMap(); public void…
jrharshath
  • 25,975
  • 33
  • 97
  • 127
69
votes
3 answers

Sort a part of a list in place

Let's say we have a list: a = [4, 8, 1, 7, 3, 0, 5, 2, 6, 9] Now, a.sort() will sort the list in place. What if we want to sort only a part of the list, still in place? In C++ we could write: int array = { 4, 8, 1, 7, 3, 0, 5, 2, 6, 9 }; int * ptr…
Headcrab
  • 6,838
  • 8
  • 40
  • 45
68
votes
7 answers

How to remove trailing whitespaces for multiple files?

Are there any tools / UNIX single liners which would remove trailing whitespaces for multiple files in-place. E.g. one that could be used in the conjunction with find.
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435
45
votes
1 answer

Pandas: peculiar performance drop for inplace rename after dropna

I have reported this as an issue on pandas issues. In the meanwhile I post this here hoping to save others time, in case they encounter similar issues. Upon profiling a process which needed to be optimized I found that renaming columns NOT inplace…
eldad-a
  • 3,051
  • 3
  • 22
  • 25
1
2 3
25 26