reverse

Django Reverse Query in Template

让人想犯罪 __ 提交于 2019-12-18 11:07:56
问题 I have models like this class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() def __unicode__(self): return self.name class Entry(models.Model): blog = models.ForeignKey(Blog) headline = models.CharField(max_length=255) I want to list all blogs in a page. I have written a view such that def listAllBlogs(request): blogs= Blog.objects.all() return object_list( request, blogs, template_object_name = "blog", allow_empty = True, ) And I can display tagline

Reversing characters in each word in a sentence - Stack Implementation

二次信任 提交于 2019-12-18 09:46:25
问题 This code is inside the main function: Scanner input = new Scanner(System.in); System.out.println("Type a sentence"); String sentence = input.next(); Stack<Character> stk = new Stack<Character>(); int i = 0; while (i < sentence.length()) { while (sentence.charAt(i) != ' ' && i < sentence.length() - 1) { stk.push(sentence.charAt(i)); i++; } stk.empty(); i++; } And this is the empty() function: public void empty() { while (this.first != null) System.out.print(this.pop()); } It doesn't work

Python reverse() for palindromes

点点圈 提交于 2019-12-18 08:08:18
问题 I'm just getting started in python, and I'm trying to test a user-entered string as a palindrome. My code is: x=input('Please insert a word') y=reversed(x) if x==y: print('Is a palindrome') else: print('Is not a palindrome') This always returns false because y becomes something like <reversed object at 0x00E16EF0> instead of the reversed string. What am I being ignorant about? How would you go about coding this problem? 回答1: Try y = x[::-1] . This uses splicing to get the reverse of the

ggplot2: Reversing secondary continuous x axis

佐手、 提交于 2019-12-18 07:20:58
问题 I am trying to reverse the secondary X axis on top of my ggplot. ggplot( data=MasterTable, aes(x=Concentration, y=Signal, color=factor(Assay))) + scale_x_continuous("Chemical 1", sec.axis = sec_axis(~ . *1, name = "Chemical 2"), scale_x_reverse(limits=c(400,0))) If you remove the last section of the code ( scale_x_reverse ...) it makes a plot with a secondary that is identical to the bottom X axis. I have managed to reverse the bottom axis but this also reverses the top axis. I am looking to

ggplot2: Reversing secondary continuous x axis

流过昼夜 提交于 2019-12-18 07:20:13
问题 I am trying to reverse the secondary X axis on top of my ggplot. ggplot( data=MasterTable, aes(x=Concentration, y=Signal, color=factor(Assay))) + scale_x_continuous("Chemical 1", sec.axis = sec_axis(~ . *1, name = "Chemical 2"), scale_x_reverse(limits=c(400,0))) If you remove the last section of the code ( scale_x_reverse ...) it makes a plot with a secondary that is identical to the bottom X axis. I have managed to reverse the bottom axis but this also reverses the top axis. I am looking to

Reversing a list slice in python

跟風遠走 提交于 2019-12-18 06:19:07
问题 I am trying to reverse slice of a list in python but it returns an empty list. But when I try with whole list, it works fine. Am I missing anything here? l=[1,2,3,4,5,6,7,8] l[::-1]=[8, 7, 6, 5, 4, 3, 2, 1] <<< This worked fine. l[2:5]=[3, 4, 5] l[2:5:-1]=[] <<< Expecting [5,4,3] here. Any clues? 回答1: The syntax is always [start:end:step] so if you go backwards your start needs to be greater than the end. Also remember that it includes start and excludes end, so you need to subtract 1 after

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

岁酱吖の 提交于 2019-12-17 23:45:14
问题 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'), url(r'^depict$', cyclops.django.depict, name="cyclops-depict"), I can go to that URL and get the 200x200 PNG that was constructed, so I know that part works. In my template from the "cansmi.cansmi" response I want to construct a URL for the named template "cyclops-depict"

How can I sort tuples by reverse, yet breaking ties non-reverse? (Python)

爷,独闯天下 提交于 2019-12-17 18:55:24
问题 If I have a list of tuples: results = [('10', 'Mary'), ('9', 'John'), ('10', 'George'), ('9', 'Frank'), ('9', 'Adam')] How can I sort the list as you might see in a scoreboard - such that it will sort the score from biggest to smallest, but break ties alphabetically by name? So after the sort, the list should look like: results = [('10', 'George'), ('10', 'Mary'), ('9', 'Adam'), ('9', 'Frank'), ('9', 'John')] At the moment all I can do is results.sort(reverse=True) , but breaks ties reverse

how to calculate reverse modulus

…衆ロ難τιáo~ 提交于 2019-12-17 14:54:37
问题 now I have one formula: int a = 53, x = 53, length = 62, result; result = (a + x) % length; but how to calculate reverse modulus to get the smallest "x" if I known result already (53 + x) % 62 = 44 //how to get x i mean what's the formula or logic to get x 回答1: private int ReverseModulus(int div, int a, int remainder) { if(remainder >= div) throw new ArgumentException("Remainder cannot be greater than or equal to divisor"); if(a < remainder) return remainder - a; return div + remainder - a; }

Recursive Prolog predicate for reverse / palindrome

我的未来我决定 提交于 2019-12-17 13:55:44
问题 Can I get a recursive Prolog predicate having two arguments, called reverse, which returns the inverse of a list: Sample query and expected result: ?- reverse([a,b,c], L). L = [c,b,a]. A recursive Prolog predicate of two arguments called palindrome which returns true if the given list is palindrome. Sample query with expected result: ?- palindrome([a,b,c]). false. ?- palindrome([b,a,c,a,b]). true. 回答1: Ad 1: It is impossible to define reverse/2 as a ( directly edit thx to @repeat: tail)