Add content on to the beginning of something (usually a file).
Questions tagged [prepend]
475 questions
635
votes
6 answers
What's the idiomatic syntax for prepending to a short python list?
list.append() is the obvious choice for adding to the end of a list. Here's a reasonable explanation for the missing list.prepend(). Assuming my list is short and performance concerns are negligible, is
list.insert(0, x)
or
list[0:0] =…
![](../../users/profiles/407845.webp)
hurrymaplelad
- 23,777
- 9
- 50
- 72
292
votes
10 answers
Most efficient way to prepend a value to an array
Assuming I have an array that has a size of N (where N > 0), is there a more efficient way of prepending to the array that would not require O(N + 1) steps?
In code, essentially, what I currently am doing is
function prependArray(value, oldArray) {
…
![](../../users/profiles/721376.webp)
samccone
- 9,746
- 5
- 39
- 50
217
votes
9 answers
.append(), prepend(), .after() and .before()
I am pretty proficient with coding, but now and then I come across code that seems to do basically the same thing. My main question here is, why would you use .append() rather then .after() or vice verses?
I have been looking and cannot seem to…
![](../../users/profiles/1481785.webp)
Epik
- 3,159
- 4
- 14
- 23
154
votes
11 answers
How can I implement prepend and append with regular JavaScript?
How can I implement prepend and append with regular JavaScript without using jQuery?
![](../../users/profiles/342984.webp)
Ben
- 23,101
- 33
- 104
- 161
144
votes
17 answers
Unix command to prepend text to a file
Is there a Unix command to prepend some string data to a text file?
Something like:
prepend "to be prepended" text.txt
![](../../users/profiles/1293653.webp)
One Two Three
- 18,931
- 22
- 63
- 100
118
votes
6 answers
Adding code to a javascript function programmatically
I'm attempting to customize an existing JS library without modifying the original JS code. This code loads in a few external JS files which I do have access to, and what I'd like to do is change one of the functions contained in the original file…
![](../../users/profiles/387885.webp)
Munzilla
- 3,595
- 5
- 26
- 35
103
votes
8 answers
How to insert element as a first child?
I want to add a div as a first element using jquery on each click of a button
77
votes
10 answers
Prepend a line to an existing file in Python
I need to add a single line to the first line of a text file and it looks like the only options available to me are more lines of code than I would expect from python. Something like this:
f = open('filename','r')
temp = f.read()
f.close()
f =…
![](../../users/profiles/9137.webp)
Nick
- 9,425
- 7
- 45
- 59
77
votes
2 answers
D3.js prepend (similar to jQuery prepend)
I like the usage of append in D3, and I'm looking for prepend.
Does this exist in D3?
![](../../users/profiles/1806399.webp)
Mia
- 5,410
- 8
- 41
- 74
69
votes
4 answers
Prepend std::string
What is the most efficient way to prepend std::string? Is it worth writing out an entire function to do so, or would it take only 1 - 2 lines? I'm not seeing anything related to an std::string::push_front.
![](../../users/profiles/763053.webp)
zeboidlund
- 8,829
- 25
- 108
- 176
59
votes
5 answers
What is the idiomatic way to prepend to a vector in Clojure?
Prepending to a list is easy:
user=> (conj '(:bar :baz) :foo)
(:foo :bar :baz)
Appending to a vector is easy:
user=> (conj [:bar :baz] :foo)
[:bar :baz :foo]
How do I (idiomatically) prepend to a vector, while getting back a vector?
This does not…
![](../../users/profiles/147058.webp)
0x89
- 2,762
- 2
- 27
- 30
46
votes
2 answers
What's the difference between `::` and `+:` for prepending to a list)?
List has 2 methods that are specified to prepend an element to an (immutable) list:
+: (implementing Seq.+:), and
:: (defined only in List)
+: technically has a more general type signature—
def +:[B >: A, That](elem: B)(implicit bf:…
![](../../users/profiles/319931.webp)
Mechanical snail
- 26,499
- 14
- 83
- 107
43
votes
6 answers
jquery - keep window from changing scroll position while prepending items to a list?
I have a page that displays messages and I want it to work just like Facebook, but without the lazy loader. Messages are displayed in chronological order, most recent last.
My message list is initially populated x number of most recent messages, and…
![](../../users/profiles/591736.webp)
Redtopia
- 4,036
- 6
- 43
- 65
34
votes
3 answers
How to prepend int to slice
I am fairly new to Go and thus my question might seem a bit naive.
I have a slice which I created using
var x []int;
for i := 2; i < 10; i += 2 {
x = append(x, i);
}
I want to prepend an integer to this slice, something like
x = append(2,…
![](../../users/profiles/2525417.webp)
coda
- 1,129
- 2
- 13
- 22
27
votes
2 answers
What is the difference between 'include' and 'prepend' in Ruby?
From the Module
Module#append_features(mod) → mod => When this module is included in another, Ruby calls append_features in this module, passing it the receiving module in mod. Ruby’s default implementation is to add the constants, methods, and…
![](../../users/profiles/2767755.webp)
Arup Rakshit
- 109,389
- 25
- 234
- 293