How to reverse lines of a text file?
In GNU coreutils, there’s tac(1)
In GNU coreutils, there’s tac(1)
That question gets asked a lot. When I was asked it in my interviews many years ago, I reasoned as follows: a singly-linked list is essentially a stack. Reversing a linked list is therefore a trivial operation on stacks: newList = emptyList; while(!oldList.IsEmpty()) newList.Push(oldList.Pop()); Now all you have to do is implement IsEmpty and Push … Read more
Reverse column A, take the cumsum, then reverse again: df[‘C’] = df.loc[::-1, ‘A’].cumsum()[::-1] import pandas as pd df = pd.DataFrame( {‘A’: [False, True, False, False, False, True, False, True], ‘B’: [0.03771, 0.315414, 0.33248, 0.445505, 0.580156, 0.741551, 0.796944, 0.817563],}, index=[6, 2, 4, 7, 3, 1, 5, 0]) df[‘C’] = df.loc[::-1, ‘A’].cumsum()[::-1] print(df) yields A B C … Read more
Check if the upstream source has gzip turned on, if so you need proxy_set_header Accept-Encoding “”; so the whole thing would be something like location / { proxy_set_header Accept-Encoding “”; proxy_pass http://upstream.site/; sub_filter_types text/css; sub_filter_once off; sub_filter .upstream.site special.our.domain; } Check these links https://www.ruby-forum.com/topic/178781 https://forum.nginx.org/read.php?2,226323,226323 http://www.serverphorums.com/read.php?5,542078
YGL’s answer is the right one for log, see this thread: The hint from “hg help log” might be: “If no revision range is specified, the default is tip:0”. Combine this with the knowlegde from “hg help multirevs”. That is: hg log -r : multirevs: When Mercurial accepts more than one revision, they may be … Read more
A solution close to what you have already tried is to use: >>> football[football.columns[::-1]] losses wins team year 0 5 11 Bears 2010 1 8 8 Bears 2011 2 6 10 Bears 2012 3 1 15 Packers 2011 4 5 11 Packers 2012 5 10 6 Lions 2010 6 6 10 Lions 2011 7 12 … Read more
As long as you’re dealing with simple ASCII characters, and you’re happy to use built-in functions, this will work: function reverse(s){ return s.split(“”).reverse().join(“”); } If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny. You might want … Read more
Avoid indexes altogether? How about: for (ListIterator iterator = list.listIterator(list.size()); iterator.hasPrevious();) { final Object listElement = iterator.previous(); }
It is worth noting that the list method is a lot older than the extension method. The naming was likely kept the same as Reverse seems more succinct than BackwardsIterator. If you want to bypass the list version and go to the extension method, you need to treat the list like an IEnumerable<T>: var numbers … Read more