Is there a built-in that removes duplicates from list in Python, whilst preserving order? I know that I can use a set to remove duplicates, but that destroys the original order. I also know that I can roll my own like this:
def uniq(input):
output = []
for x in input:
if x not in output:
output.append(x)
return output
...
Refering to a previously asked question, I would like to know how to get the title of the current active document.
I tried the script mention in the answers to the question above. This works, but only gives me the name of the application. For example, I am writing this question: When I fire up the script it gives me the name of the appl...
In python, if you create a circle with:
newcircle = circle(center_x, center_y, radius)
How do you test if a given set of x/y coordinates are inside the circle?
...
hi,
i have a list of regex patterns (stored in a list type) that I would like to apply to a string.
Does anyone know a good way to:
Apply every regex pattern in the list to the string
and
Call a different function that is associated with that pattern in the list if it matches.
I would like to do this in python if possible
thanks ...
A regular function can contain a call to itself in its definition, no problem. I can't figure out how to do it with a lambda function though for the simple reason that the lambda function has no name to refer back to. Is there a way to do it? How?
...
I need to read some large files (from 50k to 100k lines), structured in groups separated by empty lines. Each group start at the same pattern "No.999999999 dd/mm/yyyy ZZZ". Here´s some sample data.
No.813829461 16/09/1987 270
Tit.SUZANO PAPEL E CELULOSE S.A. (BR/BA)
C.N.P.J./C.I.C./N INPI : 16404287000155
Procurador: MARCEL...
After seeing the abilities and hackibility of wiimotes I really want to use it in my 'Intro to programming' final. Everyone must make a python program and present it to the class.
I want to make a game with pygame incorporating a wiimote. I found pywiiuse which is a very basic wrapper for the wiiuse library using c types.
I can NOT g...
I am writing a server, and I branch each action off into a thread when the request is incoming. I do this because almost every request is a database query. I am using a threadpool library to cut down on construction/destruction of threads.
My question is though - what is a good cutoff point for I/O threads like these? I know it would ju...
I am using python-ldap to try to authenticate against an existing Active Directory, and when I use the following code:
import ldap
l = ldap.initialize('LDAP://example.com')
m = l.simple_bind_s([email protected],password)
I get the following back:
print m
(97, [])
What does the 97 and empty list signify coming from a Microsoft Ac...
Is there a way to do the following preprocessor directives in Python?
#if DEBUG
< do some code >
#else
< do some other code >
#endif
...
I have a script that loops through a series of four (or less) characters strings. For example:
aaaa
aaab
aaac
aaad
If have been able to implement it with nested for loops like so:
chars = string.digits + string.uppercase + string.lowercase
for a in chars:
print '%s' % a
for b in chars:
print '%s%s' % (a, b)
...
As someone new to GUI development in Python (with pyGTK), I've just started learning about threading. To test out my skills, I've written a simple little GTK interface with a start/stop button. The goal is that when it is clicked, a thread starts that quickly increments a number in the text box, while keeping the GUI responsive.
I've go...
I've been looking around the internet for a Java scientific package that is "similar" to Scipy. The only thing I have really found is JScience but it seems not to offer plotting and such. Does anyone know of a good scientific package for Java?
...
I have a file that contains the symbol table details.Its in the form of rows and columns.
I need to extract first and last column.
How can I do that?
...
I would like to know how to convert a string containing digits to a double.
...
Is there a good ORM (object relational manager) solution that can use the same database from C++, C#, Python?
It could also be multiple solutions, e.g. one per language, as long as they can can access the same database and use the same schema.
Multi platform support is also needed.
Clarification:
The idea is to have one database and ...
Hi to all,
i have a module (a single .py file, actually), with a class called HashedDir.
when i import the file and instanciate 2 instances of that class, when i check the object's fields they're always the same, even if the two objects should be different.
Eg:
h1 = HashedDir('/path/to/dir')
print h1.getList()['files'] # /path/to/di...
I want to stop a Python script on seeing an error message.
I dont want any error message on shell like exit().
How to do it ???
...
Given a dictionary likeso:
map = { 'a': 1, 'b':2 }
How can one invert this map to get:
inv_map = { 1: 'a', 2: 'b' }
...
I was trying to write some code that would check if an item has some attributes , and to call them . I tried to do that with getattr , but the modifications wouldn't be permanent . I made a "dummy" class to check upon this .
Here is the code I used for the class :
class X:
def __init__(self):...