|
Hi, yeah! i make it with CURL!
Thanks
|
|
|
|
|
i would like u to help me write a python function that takes a string and returns true if the string is a palindrome,false otherwise.
|
|
|
|
|
Homework, huh?
Ok... what have you tried to do?
We are using Linux daily to UP our productivity - so UP yours!
|
|
|
|
|
nanjekye joannah wrote: python function that takes a string and returns true if the string is a palindrome
So...
A quick and dirty solution:
Start slicing off first and last letter of the string, and check if they are the same. If you find a mismatching pair, return false immidiately. Carry on until you're left with at most one letter, at which point you return true, as the string is a palindrome.
Φευ! Εδόμεθα υπό ρηννοσχήμων λύκων!
(Alas! We're devoured by lamb-guised wolves!)
|
|
|
|
|
Try this:
def isPalindrome(s)
return s == s[::-1]
Steve
|
|
|
|
|
Hi Steve
I'm just getting started in Python, and came across your response to the "Palindrome" problem whilst browsing the forum to pick up tips.
It's a really elegant compact solution - I wish I could write code like that! - but there seems to be a heck of a lot of stuff going on in that one short line, and as a newbie I confess that I don't fully understand the syntax.
I know it is using string slicing, but haven't seen a string slicing command take 3 parameters before, and also be part of a conditional Boolean statement in the same line of code.
It would really help my understanding if you could describe exactly how your statement does its magic!
Many thanks in anticipation
Dave
(Swansea, UK)
|
|
|
|
|
Been playing with string slicing... think I get it now...
I didn't realise that you could specify a third parameter for string slicing.
In fact the syntax for string slicing parameters seems very similar to that used in the "range" function - i.e. "[start:stop:step]".
So [:] means "include characters starting from character index 0 (i.e. start from the very first character) and end at the character at index (end-1) (i.e. finish at the last character) - i.e. "take the whole string"
...and [::-1] means "take the whole string of characters, but read it starting from the end and stepping backwards one character at a time"
So if the string equals itself written backwards, Boolean s == s[::-1] is True, and isPalindrome returns "True"
If the string is not equal to itself written backwards, Boolean s == s[::-1] is False, and isPalindrome returns "False".
Easy when you know how, and very neat!
Thanks again
Dave
|
|
|
|
|
I'm new to Python and string objects. I can manipulate them but this trick is really cool. This is what I through together using recursion real quick:
def isPalindrome(str):
"""Parses string and tests if palindromic; Returns True or False"""
if len(str) <= 1:
return True;
if str[0] != str[-1]:
return False
return isPalindrome(str[1:-1])
But using your simpler method:
def isPal(str):
return str == str[::-1]
Thanks a lot for that post!
modified on Thursday, February 24, 2011 11:55 AM
|
|
|
|
|
Hi,
I have a device(mote) that monitor temperature, light and sound. It transmit the data to PC using wireless and store in a database (PostgreSQL). After storing the data, i have it exported out becoming a .sql extenstion file. I will be only able to view the data via a program provided by the device company.
The main aim of my project is to make data viewable on html where im able to publish it online.
Where i will be using the output data (.sql file) and publish it on html using PERL and CGI.
Any helps on how i can make the .sql file readable in PERL or do i need another program to read the database output(.sql file) then making PERL script able to read the filen and then publish it online?
The device I'm using which is made by Xbow and im running Win XP.
Any help would be greatly appreciated.
Regards
Joseph
|
|
|
|
|
You can read the database using perl. There are libraries for that.
You can create html using perl. There are libraries for that.
And of course perl does CGI.
Presumably you already have a way to host on the internet that supports CGI.
|
|
|
|
|
So, a while ago I wrote here about starting to experiment with Django, and now I have come to a stop...
I usually map my Django projects on the root, but this time I tried something different and failed very badly...
I tried to map it to http://foo.com/django and encountered two problems, I hope you guys can help me with...
Problem 1:
If I go to address http://foo.com/django (without trailing slash) I get an Internal Server Error.
Log shows this info:
File "/var/lib/python-support/python2.5/django/middleware/common.py", line 41, in process_request
if settings.APPEND_SLASH and (old_url1-1 != '/') and ('.' not in old_url1.split('/')-1):
IndexError: string index out of range
If I include the trailing slash it works (at least it seems to).
APPEND_SLASH is (obviously) set to True.
Problem 2:
Let's go with urls.py that looks like this:
from django.conf.urls.defaults import *
from djangobook.views import hello
urlpatterns = patterns('',
(r'^hello/$', hello),
)
Instead of going to http://foo.com/django/hello I get redirected to http://foo.com/hello. I presume I'm missing a setting or something to make it relative to the project's starting URL?
We are using Linux daily to UP our productivity - so UP yours!
|
|
|
|
|
When you deploy on a subdirectory you will need to make sure you account for that in your url patterns. Take a look here.[^]
And above all things, never think that you're not good enough yourself. A man should never think that. My belief is that in life people will take you at your own reckoning. --Isaac Asimov
Avoid the crowd. Do your own thinking independently. Be the chess player, not the chess piece. --Ralph Charell
|
|
|
|
|
So, all the url patterns have to start with '/django/ ' ?
Besides, there are no instructions for mod_wsgi, or I can't see them?
We are using Linux daily to UP our productivity - so UP yours!
|
|
|
|
|
You shouldn't need to make any mod_wsgi changes. And don't copy the apache config on the link, it looks like it would kill you app since it seems to be a mod_python set-up. So, try to leave you apache config alone and start with your patterns.
And above all things, never think that you're not good enough yourself. A man should never think that. My belief is that in life people will take you at your own reckoning. --Isaac Asimov
Avoid the crowd. Do your own thinking independently. Be the chess player, not the chess piece. --Ralph Charell
|
|
|
|
|
Ok, so what I just figured is that I get redirected from foo.com/django/hello to coo.com/hello only if I leave the trailing slash.
How can I make django append the trailing slash in the URL? APPEND_SLASH is set to true.
We are using Linux daily to UP our productivity - so UP yours!
|
|
|
|
|
Hello All,
My co-worker has a script that was caught in a infinite loop... during one run of the script. It has not repeated this behaviour since.
After reading the docs online (w3schools http://www.w3schools.com/php/func_directory_dir.asp[^]) I see this returns a directory stream.
I am wondering if you use the objects function "read()" as the condition of a while loop...
<br />
$dir = dir('/pathway/to/directory');<br />
while($dir->read()!==false)<br />
{<br />
... process files...<br />
}<br />
...is it possible to cause an infinite loop when a new file is added via a different script to the same directory during this scripts execution?
the scripts run on a lamp system with ample resources.
Ideas?
|
|
|
|
|
Well I am not sure but according to OS fundamentals these things should be possible,
1) Rename and delete of directory not allowed
2) Rename and delete (and editing) is not allowed for the file getting processed in current loop instance
3) One should be able to rename or delete or editing a file which is not getting processed in current loop instance
4) One should be able to add new file in that directory.
These all are theoretically, one can omit or change these rules for his OS. And sorry I haven't tried the situation you gave. But I think it should be possible. And it might led to infinite loop.
|
|
|
|
|
chevu,
Thank you for your response. To be clearer I should state the process files was really just reading file names...I'm not sure that it matters.
The script is still behaving normally, so I can only think that it was a fluke or maybe a sign of system instability (power suppply maybe).
All the best!
cjoki
|
|
|
|
|
cjoki,
As per the mutual exclusion fundamental no mater what you are doing (read/write) with data (in this case reading file name) you cannot change that name.
Ya but you might have seen in windows or unix or linux that in if you have opened one folder at two differ location and you add one file/folder at one place changes get reflected to another place. I am not so sure about windows directroy structure in detail. But for unix I know that once you add new file in directory its inode will be added to director file structure list and those changes can be read using directory structure. I dont know whether I am able to clarify your doubt or not. It will be better if you find out such script is working on your system and if it is not working then try to run such script and check. In both case please let me know the result I would like to know whether it is possible or not.
Thanks.
|
|
|
|
|
hello guys, i have a problem with a query.
I have a table actions which has no primary key. any one particular record can be identified by the combination of actionID, taskID and ProjectID which are the other fields in actions table.
Here is an example of the possible situations of entries in the actions table(so that you get an idea of what i am talking about)
ActionID 1 for taskID 1 of ProjectID 10-000
ActionID 2 for taskID 1 of ProjectID 10-000
ActionID 1 for taskID 2 of ProjectID 10-000
ActionID 1 for taskID 2 of ProjectID 10-001
ActionID 2 for taskID 2 of ProjectID 10-001
ActionID 3 for taskID 1 of ProjectID 10-000
ActionID 1 for taskID 1 of ProjectID 10-002
ActionID 1 for taskID 2 of ProjectID 10-003
When i am creating a new action for taskID 1 of ProjectID 10-000, then what i am doing is i am scanning the all the ActionIDs of the taskID 1 of ProjectID 10-000, ordered by ActionID and incrementing the last obtained ActionID by 1 to generate a new ActionID for the new action.
Now suppose the entries of ActionID for taskID 1 of ProjectID 10-000 in the database are 1,2,5,6,8,10,15,16, then according to my logic, the newly generated ActionID would be 17, but that is not what i want. I want the newly generated ActionID to be 3, because 3 is not present in the ActionID field of taskID 1 of ProjectID 10-000 combination .
In the above example, if i delete ActionID 2 for taskID 1 of ProjectID 10-000 and then when a new action is added to the same combination of taskID and ProjectID, i want the newly generated ActionID to be 2 and not 4 which is what i am getting from my logic.
Can anyone help me with this???
|
|
|
|
|
i got it ..
iam not pro. with php .. but as i see it , it could solve by comparing the exist value with acounter
like
$i =0;
while ($id = mysql_fetch_object($result)) {
$i +=1;
if ( $id->id != $i) {
echo "ID num $i is missing";
break;
}
}
|
|
|
|
|
Hi all,
I have done a project in php.Now i want to make an setup file (i.e., an exe) of the project so that i can install any where.
Is it possible in php.If yes then how can i do it.
Thanks in advance.
|
|
|
|
|
use it's possible
http://www.bambalam.se/bamcompile/
use that compiler
|
|
|
|
|
Hi all,
I need a help regarding exporting a html file to pdf file in PHP.How can i do this ?
Thanks in advance.
|
|
|
|
|
You could look into using OpenOffice.org headless.
There are also some PHP libraries for writing PDF - http://www.fpdf.org/[^] is one that doesn't need any extensions installed.
|
|
|
|