Questions tagged [reverse]

Rearranging the order of a sequence such that the final order is a mirror image of the original.

Rearranging the order of a sequence such that the final order is a mirror image of the original.

3773 questions
42
votes
10 answers

How do I reverse a String in Dart?

I have a String, and I would like to reverse it. For example, I am writing an AngularDart filter that reverses a string. It's just for demonstration purposes, but it made me wonder how I would reverse a string. Example: Hello, world should turn…
Seth Ladd
  • 112,095
  • 66
  • 196
  • 279
42
votes
43 answers

Reverse a string without using reversed() or [::-1]?

I came across a strange Codecademy exercise that required a function that would take a string as input and return it in reverse order. The only problem was you could not use the reversed method or the common answer here on stackoverflow,…
samrap
  • 5,595
  • 5
  • 31
  • 56
41
votes
12 answers

Translate integer to letters and vice versa (e.g. 0 = "A", 26 = "AA", 27 = "AB")

So I have this function: function toAlpha($data){ $alphabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'); $alpha_flip = array_flip($alphabet); if($data <= 25){ …
pillarOfLight
  • 8,592
  • 15
  • 60
  • 90
41
votes
6 answers

How do I construct a Django reverse/url using query args?

I have URLs like http://example.com/depict?smiles=CO&width=200&height=200 (and with several other optional arguments) My urls.py contains: urlpatterns = patterns('', (r'^$', 'cansmi.index'), (r'^cansmi$', 'cansmi.cansmi'), …
Andrew Dalke
  • 14,889
  • 4
  • 39
  • 54
41
votes
3 answers

Sort a list of tuples by second value, reverse=True and then by key, reverse=False

I need to sort a dictionary by first, values with reverse=True, and for repeating values, sort by keys, reverse=False So far, I have this dict = [('B', 3), ('A', 2), ('A', 1), ('I', 1), ('J', 1)] sorted(dict.items(), key=lambda x: (x[1],x[1]),…
Nicolas Hung
  • 595
  • 1
  • 6
  • 15
40
votes
27 answers

Reverse each individual word of "Hello World" string with Java

I want to reverse each individual word of a String in Java (not the entire string, just each individual word). Example: if input String is "Hello World" then the output should be "olleH dlroW".
Vicheanak
  • 6,444
  • 17
  • 64
  • 98
39
votes
6 answers

Reverse A Binary Tree (Left to Right)

I was looking at interview questions and I recently came upon one that asked you how to reverse a general binary tree, like flip it from right to left. So for example if we had the binary tree 6 / \ 3 4 / \ / \ 7 3 8 …
user1234831
  • 409
  • 1
  • 4
  • 5
37
votes
3 answers

Why there is two completely different version of Reverse for List and IEnumerable?

For the List object, we have a method called Reverse(). It reverse the order of the list 'in place', it doesn't return anything. For the IEnumerable object, we have an extension method called Reverse(). It returns another IEnumerable. I need to…
Cyril Gandon
  • 16,830
  • 14
  • 78
  • 122
34
votes
9 answers

Reverse iteration through ArrayList gives IndexOutOfBoundsException

When I reverse iterate over an ArrayList I am getting a IndexOutOfBoundsException. I tried doing forward iteration and there is no problem. I expect and know that there are five elements in the list. The code is below: Collection rtns =…
Ankur
  • 50,282
  • 110
  • 242
  • 312
34
votes
11 answers

Iterate in reverse through an array with PHP - SPL solution?

Is there an SPL Reverse array iterator in PHP? And if not, what would be the best way to achieve it? I could simply do $array = array_reverse($array); foreach($array as $currentElement) {} or for($i = count($array) - 1; $i >= 0; $i--) { } But is…
Sebastian Hoitz
  • 9,343
  • 13
  • 61
  • 77
34
votes
3 answers

Reverse DataFrame column order

I want to simply reverse the column order of a given DataFrame. My DataFrame: data = {'year': [2010, 2011, 2012, 2011, 2012, 2010, 2011, 2012], 'team': ['Bears', 'Bears', 'Bears', 'Packers', 'Packers', 'Lions', 'Lions', 'Lions'], 'wins':…
Boosted_d16
  • 13,340
  • 35
  • 98
  • 158
32
votes
7 answers

Can I get hg log to print the history in reverse order?

If not, is this a feature that git has?
Erik B
  • 40,889
  • 25
  • 119
  • 135
31
votes
9 answers

How to reverse lines of a text file?

I'm writing a small shell script that needs to reverse the lines of a text file. Is there a standard filter command to do this sort of thing? My specific application is that I'm getting a list of Git commit identifiers, and I want to process them in…
Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
31
votes
1 answer

http_sub_module / sub_filter of nginx and reverse proxy not working

I am trying to reverse proxy my website and modify the content. To do so, I compiled nginx with sub_filter. It now accepts the sub_filter directive, but it does not work somehow. server { listen 8080; server_name www.xxx.com; …
thms0
  • 494
  • 1
  • 7
  • 15
30
votes
13 answers

Reversing single linked list in C#

I am trying to reverse a linked list. This is the code I have come up with: public static void Reverse(ref Node root) { Node tmp = root; Node nroot = null; Node prev = null; while (tmp != null) { //Make a…
Nemo
  • 4,601
  • 11
  • 43
  • 46