Is there a way to get the timezone of the connecting user using Pylons, and to adjust the content before rendering accordingly? Or can this only be done by JS?
Thanks.
I want to know how to find if there is a certain amount of consecutive numbers in a row in my list e.g.
For example if I am looking for two 1's then:
list = [1, 1, 1, 4, 6] #original list
list = ["true", "true", 1, 4, 6] #after my function has been through the list.
If I am looking for three 1's then:
list = [1, 1, 1, 4, 6] #original list
list = ["true", "true", "true", 4, 6] #after my function has been through the list.
I have tried:
list = [1, 1, 2, 1]
1,1,1 in list #typed into shell, returns "(1, 1, True)"
Any help would be greatly appreciated, I mainly would like to understand whats going on, and how to check if the next element in the list is the same as the first x amount.
is there a way that if the following class is created; I can grab a list of attributes that exist. (this class is just an bland example, it is not my task at hand)
class new_class():
def __init__(self, number):
self.multi = int(number) * 2
self.str = str(number)
a = new_class(2)
print(', '.join(a.SOMETHING))
* the attempt is that "multi, str" will print. the point here is that if a class object has attributes added at different parts of a script that I can grab a quick listing of the attributes which are defined.
Write two functions, called countSubStringMatch and countSubStringMatchRecursive that take two arguments, a key string and a target string. These functions iteratively and recursively count the number of instances of the key in the target string. You should complete definitions for
def countSubStringMatch(target,key):
and
def countSubStringMatchRecursive (target, key):
For the remaining problems, we are going to explore other substring matching ideas. These problems can be solved with either an iterative function or a recursive one. You are welcome to use either approach, though you may find iterative approaches more intuitive in these cases of matching linear structures.
Hello.
For my project I would be using the argparse library. My question is, how do I distribute it with my project. I am asking this because of the technicalities and legalities involved.
Do I just:
Put the argparse.py file along with
my project. That is, in the tar file for my project.
Create a package for it for my
distro?
Tell the user to install it himself?
Sorry for being such a noob, but I new to all this.
I open a website with urlopen. I then put the website sourcecode into a variable like so
source = website.read()
When I just print the source it comes out formatted correctly, however when I try to iterate through each line each character is it's own line.
for example
when I just print it looks like this
<HTML> title</html>
When I do this
for line in source:
print line
it looks like this
<
H
T
M
L
... etc
I need to find a string that starts with "var" and then print that entire line.
I have a simple GAE app that includes a login/logout link. This app is running on the dev server at the moment.
The base page handler gets the current user, and creates a login/logout url appropriately. It then puts this information into a _template_data dictionary, for convenience of subclasses.
class BasePage(webapp.RequestHandler):
_user = users.get_current_user()
_login_logout_link = None
if _user:
_login_logout_link = users.create_logout_url('/')
else:
_login_logout_link = users.create_login_url('/')
_template_data = {}
_template_data['login_logout_link'] = _login_logout_link
_template_data['user'] = _user
def render(self, templateName, templateData):
path = os.path.join(os.path.dirname(__file__), 'Static/Templates/%s.html' % templateName)
self.response.out.write(template.render(path, templateData))
Here is one such subclass:
class MainPage(BasePage):
def get(self):
self.render('start', self._template_data)
The login/logout link is displayed fine, and going to the correct devserver login/logout page. However, it seems to have no effect - the server still seems to think the user is logged out. What am I doing wrong here?
Is there a fast way to check if one set entirely contains another?
Something like:
>>>[1, 2, 3].containsAll([2, 1])
True
>>>[1, 2, 3].containsAll([3, 5, 9])
False
I have a MySql database that stores a timestamp for each record I insert. I pull that timestamp into my Android application as a string. My database is located on a server that has a TimeZone of CST. I want to convert that CST timestamp to the Android device's local time.
Can someone help with this?
I have a huge file (with around 200k inputs). The inputs are in the form:
A B C D
B E F
C A B D
D
I am reading this file and storing it in a list as follows:
text = f.read().split('\n')
This splits the file whenever it sees a new line. Hence text is like follows:
[[A B C D] [B E F] [C A B D] [D]]
I have to now store these values in a dictionary where the key values are the first element from each list. i.e the keys will be A, B, C, D.
I am finding it difficult to enter the values as the remaining elements of the list. i.e the dictionary should look like:
{A: B C D; B: E F; C: A B D; D: 0}
I have done the following:
inlinkDict = {}
for doc in text:
adoc= doc.split(' ')
docid = adoc[0]
inlinkDict[docid] = inlinkDict.get(docid,0) + {I do not understand what to put in here}
Please help as to how should i add the values to my dictionary. It should be 0 if there are no elements in the list except for the one which will be the key value. Like in example for 0.
Hi folks,
I'm looking for a way to read in c++ a text file containing numpy arrays and put the data into vector , can anyone help me out please ?
Thanks a lot.
Archy
This is a simulation of the game Cows and Bulls with three digit numbers
I am trying to get the number of cows and bulls between two numbers. One of which is generated by the computer and the other is guessed by the user. I have parsed the two numbers I have so that now I have two lists with three elements each and each element is one of the digits in the number. So:
237 will give the list [2,3,7]. And I make sure that the relative indices are maintained.the general pattern is:(hundreds, tens, units).
And these two lists are stored in the two lists: machine and person.
ALGORITHM 1
So, I wrote the following code, The most intuitive algorithm:
cows and bulls are initialized to 0 before the start of this loop.
for x in person:
if x in machine:
if machine.index(x) == person.index(x):
bulls += 1
print x,' in correct place'
else:
print x,' in wrong place'
cows += 1
And I started testing this with different type of numbers guessed by the computer.
Quite randomly, I decided on 277. And I guessed 447. Here, I got the first clue that this algorithm may not work. I got 1 cow and 0 bulls. Whereas I should have got 1 bull and 1 cow.
This is a table of outputs with the first algorithm:
Guess Output Expected Output
447 0 bull, 1 cow 1 bull, 1 cow
477 2 bulls, 0 cows 2 bulls, 0 cows
777 0 bulls, 3 cows 2 bulls, 0 cows
So obviously this algorithm was not working when there are repeated digits in the number randomly selected by the computer.
I tried to understand why these errors are taking place, But I could not. I have tried a lot but I just could not see any mistake in the algorithm(probably because I wrote it!)
ALGORITHM 2
On thinking about this for a few days I tried this:
cows and bulls are initialized to 0 before the start of this loop.
for x in range(3):
for y in range(3):
if x == y and machine[x] == person[y]:
bulls += 1
if not (x == y) and machine[x] == person[y]:
cows += 1
I was more hopeful about this one. But when I tested this, this is what I got:
Guess Output Expected Output
447 1 bull, 1 cow 1 bull, 1 cow
477 2 bulls, 2 cows 2 bulls, 0 cows
777 2 bulls, 4 cows 2 bulls, 0 cows
The mistake I am making is quite clear here, I understood that the numbers were being counted again and again.
i.e.: 277 versus 477
When you count for bulls then the 2 bulls come up and thats alright. But when you count for cows:
the 7 in 277 at units place is matched with the 7 in 477 in tens place and thus a cow is generated.
the 7 in 277 at tens place is matched with the 7 in 477 in units place and thus a cow is generated.'
Here the matching is exactly right as I have written the code as per that. But this is not what I want. And I have no idea whatsoever on what to do after this.
Furthermore...
I would like to stress that both the algorithms work perfectly, if there are no repeated digits in the number selected by the computer.
Please help me with this issue.
P.S.: I have been thinking about this for over a week, But I could not post a question earlier as my account was blocked(from asking questions) because I asked a foolish question. And did not delete it even though I got 2 downvotes immediately after posting the question.
I am hoping to write a script that will allow for the detection of video on a url and provide a download link to a *flv for google chrome.
Anyone have any suggestions were to start and get a footing?
Say I have the folowing code:
class Class1(object):
def __init__(self):
self.my_attr = 1
self.my_other_attr = 2
class Class2(Class1):
def __init__(self):
super(Class1,self).__init__()
Why does Class2 not inherit the attributes of Class1?
Hi,
I am so tired to every day at 8:00 am open Skype program to my job. I need a little script to set the hour to open and the hour to close. Sorry for my worst english.
Thanks
I want to implement a code that loops inside an array that its size is set by the user that means that the size isn't constant.
for example:
A=[1,2,3,4,5]
then I want the output to be like this:
[1],[2],[3],[4],[5]
[1,2],[1,3],[1,4],[1,5]
[2,3],[2,4],[2,5]
[3,4],[3,5]
[4,5]
[1,2,3],[1,2,4],[1,2,5]
[1,3,4],[1,3,5]
and so on
[1,2,3,4],[1,2,3,5]
[2,3,4,5]
[1,2,3,4,5]
Can you help me implement this code?
I need to write a recursive function that can add two numbers (x, y), assuming y is not negative. I need to do it using two functions which return x-1 and x+1, and I can't use + or - anywhere in the code. I have no idea how to start, any hints?
I need to delete some unicode symbols from the string '?????? ??????? ???????????? ??????????'
I know they exist here for sure. I try:
re.sub('([\u064B-\u0652\u06D4\u0670\u0674\u06D5-\u06ED]+)', '', '?????? ??????? ???????????? ??????????')
but it doesn't work. String stays the same. ant suggestion what i do wrong?
I'm trying to transfer the contents of one list to another, but it's not working and I don't know why not. My code looks like this:
list1 = [1, 2, 3, 4, 5, 6]
list2 = []
for item in list1:
list2.append(item)
list1.remove(item)
But if I run it my output looks like this:
>>> list1
[2, 4, 6]
>>> list2
[1, 3, 5]
My question is threefold, I guess: Why is this happening, how do I make it work, and am I overlooking an incredibly simple solution like a 'move' statement or something?
I'm building a program that will sum digits in a given list in a recursive way. Say, if the source list has 10 elements, the second list will have 9, the third 8 and so on until the last list that will have only one element. This is done by adding the first element to the second, then the second to the third and so on. I'm stuck without feedback from the shell. It halts without throwing any errors, then in a couple of seconds the fan is spinning like crazy.
I've read quite a few posts here and changed my approach, but I'm not sure that what have so far can produce the results I'm looking for. Thanks in advance:
#---------------------------------------------------
#functions
#---------------------------------------------------
#sum up pairs in a list
def reduce(inputList):
i = 0
while (i < len(inputList)):
#ref to current and next item
j = i + 1
#don't go for the last item
if j != len(inputList):
#new number eq current + next number
newNumber = inputList[i] + inputList[j]
if newNumber >= 10:
#reduce newNumber to single digit
newNumber = sum(map(int, str(newNumber)))
#collect into temp list
outputList.append(newNumber)
i = i + 1
return outputList;
#---------------------------------------------------
#program starts here
#---------------------------------------------------
outputList = []
sourceList = [7, 3, 1, 2, 1, 4, 6]
counter = len(sourceList)
dict = {}
dict[0] = sourceList
print '-------------'
print 'Level 0:', dict[0]
for i in range(counter):
j = i + 1
if j != counter:
baseList = dict.get(i)
#check function to understand what it does
newList = reduce(baseList)
#new key and value from previous/transformed value
dict[j] = newList
print 'Level %d: %s' % (j, dict[j])
using regedit.exe I have manually created a key in registry called
HKEY_CURRENT_USER/00_Just_a_Test_Key
and created two dword values
dword_test_1 and dword_test_2
I am trying to write some values into those two keys using following program
import _winreg
aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_CURRENT_USER)
aKey = _winreg.OpenKey(aReg, r"00_Just_a_Test_Key", 0, _winreg.KEY_WRITE)
_winreg.SetValueEx(aKey,"dword_test_1",0, _winreg.REG_DWORD, 0x0edcba98)
_winreg.SetValueEx(aKey,"dword_test_2",0, _winreg.REG_DWORD, 0xfedcba98)
_winreg.CloseKey(aKey)
_winreg.CloseKey(aReg)
I can write into the first key, dword_test_1, but when I attempt to write into the second, I get following message
Traceback (most recent call last):
File "D:/src/registry/question.py", line 7, in <module>
_winreg.SetValueEx(aKey,"dword_test_2",0, _winreg.REG_DWORD, 0xfedcba98)
ValueError: Could not convert the data to the specified type.
How do I write the second value 0xfedcba98, or any value greater than 0x7fffffff as a dword value?
Originally I was writing script to switch the "My documents" icon on or off by writing "0xf0500174" to hide or "0xf0400174" to display the icon into [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\CLSID{450D8FBA-AD25-11D0-98A8-0800361B1103}\ShellFolder]