reverse

How to use regular expressions do reverse search?

孤人 提交于 2019-12-04 19:36:39
问题 For example: My string is: 123456789 nn nn oo nn nn mlm nn203 . My target is: nn . Then, I match string from the end to the beginning and return the first match result and its postion. In this examlpe, the result is nn start in [-5] end in [-3]. I wrote the simple funcitonto do this process, but how to use regular expressions to do this job? 回答1: For the string itself, just do a findall and use the last one: import re st='123456 nn1 nn2 nn3 nn4 mlm nn5 mlm' print re.findall(r'(nn\d+)',st)[-1]

Is it possible to reverse a pseudo random number generator?

血红的双手。 提交于 2019-12-04 18:55:31
问题 Is it possible to reverse a pseudo random number generator? For example, take an array of generated numbers and get the original seed. If so, how would this be implemented? 回答1: This is absolutely possible - you just have to create a PRNG which suits your purposes. It depends on exactly what you need to accomplish - I'd be happy to offer more advice if you describe your situation in more detail. For general background, here are some resources for inverting a Linear Congruential Generator:

Recursively reversing a string in C?

…衆ロ難τιáo~ 提交于 2019-12-04 18:49:01
I have to reverse a string in a recursive function, but I cannot use loops or strlen to find where the end of the string is. Then I have to pass the reversed string back to main and copy it to a new file. Here's what I have so far: int reverse(char *str, char *strnew, int p) { char temp=str[p]; if(temp=='\0' || temp=='\n') { strnew=str; return p; } else { reverse(str++, strnew, ++p); p--; strnew[p]=str[p]; printf("strnew: %c\n", strnew[p]); return 0; } } int main(int argc, char *argv[]) { FILE *fp; char buffer[100]; char newstr[100]; int pointer=0; fp=fopen("lab8.txt", "r"); if(fp==NULL) {

Exactly when does the reverse direction of an axis apply?

偶尔善良 提交于 2019-12-04 17:07:57
Those who are familiar with XPath know that some axes, such as preceding:: , are reverse axes. And if you put a positional predicate on an expression built with a reverse axis, you may be counting backward instead of forward. E.g. $foo/preceding-sibling::*[1] returns the preceding sibling element just before $foo , not the first preceding sibling element (in document order). But then you encounter variations where this rule seems to be broken, depending on how far removed the positional predicate is from the reverse axis. E.g. ($foo/preceding-sibling::*)[1] counts forward from the beginning of

Python enumerate reverse index only

前提是你 提交于 2019-12-04 16:02:09
问题 I am trying to reverse the index given by enumerate whilst retaining the original order of the list being enumerated. Assume I have the following: >> range(5) [0, 1, 2, 3, 4] If I enumerate this I would get the following: >> list(enumerate(range(5))) [(0, 0), (1, 1), (2, 2), (3, 3), (4, 4)] However I want to reverse the index provided by enumerate so that I get: [(4, 0), (3, 1), (2, 2), (1, 3), (0, 4)] So far I have the following code: reversed(list(enumerate(reversed(range(5))))) I was just

http_sub_module / sub_filter of nginx and reverse proxy not working

▼魔方 西西 提交于 2019-12-04 11:11:53
问题 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; access_log /var/log/nginx/www.goparts.access.log main; error_log /var/log/nginx/www.goparts.error.log; root /usr/share/nginx/html; index index.html index.htm; ## send request back to apache1 ## location / { sub_filter <title> '<title>test</title>'; sub_filter_once on;

why i can't reverse a list of list in python

ぐ巨炮叔叔 提交于 2019-12-04 10:29:36
问题 i wanted to do something like this but this code return list of None (i think it's because list.reverse() is reversing the list in place): map(lambda row: row.reverse(), figure) i tried this one, but the reversed return an iterator : map(reversed, figure) finally i did something like this , which work for me , but i don't know if it's the right solution: def reverse(row): """func that reverse a list not in place""" row.reverse() return row map(reverse, figure) if someone has a better solution

jquery: reverse an order

拜拜、爱过 提交于 2019-12-04 09:17:57
问题 How can I reverse an order with jquery? I tried with the suggestion like this but it won't work! $($(".block-item").get().reverse()).each(function() { /* ... */ }); Have a look here. I want the boxed to be rearranged like this, 18 17 16 etc Thanks. 回答1: If you have a container around the list, it's a little easier: $("#container").append($(".block-item").get().reverse()); http://jsfiddle.net/BhTEN/12/ 回答2: You can use this: $($(".block-item").get().reverse()).each(function (i) { $(this).text(

How can I get the reverse url for a Django Flatpages template

前提是你 提交于 2019-12-04 07:48:42
问题 How can I get the reverse url for a Django Flatpages template 回答1: Include flatpages in your root urlconf: from django.conf.urls.defaults import * urlpatterns = patterns('', ('^pages/', include('django.contrib.flatpages.urls')), ) Then, in your view you can call reverse like so: from django.core.urlresolvers import reverse reverse('django.contrib.flatpages.views.flatpage', kwargs={'url': '/about-us/'}) # Gives: /pages/about-us/ In templates, use the {% url %} tag (which calls reverse

How can I capture which direction is being panned using UIPanGestureRecognizer?

和自甴很熟 提交于 2019-12-04 07:39:52
问题 Ok so I have been looking around at just about every option under the sun for capturing multi-touch gestures, and I have finally come full circle and am back at the UIPanGestureRecognizer. The functionality I want is really quite simple. I have setup a two finger pan gesture, and I want to be able to shuffle through some images depending on how many pixels I move. I have all that worked out okay, but I want to be able to capture if the pan gesture is REVERSED. Is there a built in way that I'm