use a set to store them:
>>> s=set()
>>> s.add('a')
>>> s.add('b')
>>> s
set(['a', 'b'])
>>> s.add('a')
>>> s
set(['a', 'b'])
>>> s.add('c')
>>> s
set(['a', 'c', 'b'])
>>>
it does remove duplicates, but is it not ordered. to order it you can
use:
>>> l=list(s)
>>> l.sort()
>>> l
['a', 'b', 'c']
It does the job.
Thanks a lot,
Ray
Peter Otten wrote:
> Rares Vernica wrote:
>
>> Is there an encode/decode error handler that can replace all the
>> not-ascii letters from iso-8859-1 with their closest ascii letter?
>
> A mapping, not an error handler, but it mig
Hi,
Does anyone know of any Unicode encode/decode error handler that does a
better replace job than the default replace error handler?
For example I have an iso-8859-1 string that has an 'e' with an accent
(you know, the French 'e's). When I use s.encode('ascii', 'replace') the
'e' will be rep
This solution I think is pretty nice:
source[:] = [x for x in source if x.lower() not in target]
Thanks a lot for all the answers,
Ray
Steven D'Aprano wrote:
> On Fri, 17 Nov 2006 12:00:46 -0800, Rares Vernica wrote:
>
>> Problem context:
>>
>> import os
>&g
The problem with skipping over them is that "walk" would still walk them
and their content. If they have a lot of other dirs and files inside
then this might end up being time consuming.
Thanks,
Ray
Neil Cerutti wrote:
> On 2006-11-17, Rares Vernica <[EMAIL PROTECTED]> wrot
Sorry for not being clear from the beginning and for not using clear
variable names.
Problem context:
import os
dirs_exclude = set(('a', 'b', 'e'))
for root, dirs, files in os.walk('python/Lib/email'):
# Task:
# delete from "dirs" the directory names from "dirs_exclude"
# case-ins
Yeah, I ended up doing a similar kind of loop. That is pretty messy.
Is there any other way?
Thanks,
Ray
Tim Chase wrote:
>> That is a nice solution.
>>
>> But, how about modifying the list in place?
>>
>> That is, l would become ['c', 'D'].
>>
>>> >>> e = ['a', 'b', 'e']
>>> >>> l = ['A', 'a'
That is a nice solution.
But, how about modifying the list in place?
That is, l would become ['c', 'D'].
Thanks a lot,
Ray
Tim Chase wrote:
>> I have a list like
>>e = ['a', 'b', 'e']
>> and another list like
>>l = ['A', 'a', 'c', 'D', 'E']
>> I would like to remove from l all the eleme
Hi,
I have the following problem:
I have a list like
e = ['a', 'b', 'e']
and another list like
l = ['A', 'a', 'c', 'D', 'E']
I would like to remove from l all the elements that appear in e
case-insensitive. That is, the result would be
r = ['c', 'D']
What is a *nice* way of doing it?
Hi,
Check out some examples:
In [16]: 9./2
Out[16]: 4.5
In [17]: 9.//2
Out[17]: 4
In [18]: 2*3
Out[18]: 6
In [19]: 2**3
Out[19]: 8
Here is the documentation for these operations:
http://docs.python.org/lib/typesnumeric.html
Regards,
Ray
Santosh Chikkerur wrote:
> Hi Friends,
> Let me know th
Hi,
I am not sure how the constants are implemented in math, but here is how
I would do it. The main idea is to declare the constants as globals in
some file.
Declare all the constants in a file:
const.py
---
pi = 3.14
Whenever you want to use pi from another file, just do:
somecode.py
---
fro
252 fc
ý=(xfd) # 253 fd
þ=(xfe)# 254 fe
é=(xe9)
ê=(xea)
ë=(xeb)
ì=(xec)
í=(xed)
î=(xee)
ï=(xef)
In [19]:
Thanks,
Ray
Frederic Rentsch wrote:
> Rares Vernica wrote:
>> Hi,
>>
>> How can I unescape HTML entities like " "?
>>
>> I know ab
e "py".
Thanks,
Ray
Frederic Rentsch wrote:
> Rares Vernica wrote:
>> Hi,
>>
>> How can I unescape HTML entities like " "?
>>
>> I know about xml.sax.saxutils.unescape() but it only deals with "&",
>> "<", and ">
Hi,
How does your code deal with ' like entities?
Thanks,
Ray
Klaus Alexander Seistrup wrote:
> Rares Vernica wrote:
>
>> How can I unescape HTML entities like " "?
>>
>> I know about xml.sax.saxutils.unescape() but it only deals with
>>
Thanks a lot for all the answers!
Ray
Frederic Rentsch wrote:
> Rares Vernica wrote:
>> Hi,
>>
>> How can I unescape HTML entities like " "?
>>
>> I know about xml.sax.saxutils.unescape() but it only deals with "&",
>> "<
Hi,
How can I unescape HTML entities like " "?
I know about xml.sax.saxutils.unescape() but it only deals with "&",
"<", and ">".
Also, I know about htmlentitydefs.entitydefs, but not only this
dictionary is the opposite of what I need, it does not have " ".
It has to be in python 2.4.
Thank
That's it. Thanks a lot!
There is no example on the locale.format in the docs so I was confused.
Regards,
Ray
deelan wrote:
> Rares Vernica wrote:
>> Hi,
>>
>> Can I use locale to format monetary values? If yes, how? If no, is
>> there something I can use?
&
Hi,
Can I use locale to format monetary values? If yes, how? If no, is there
something I can use?
E.g.,
I have 1 and I want to get "$10,000".
Thanks,
Ray
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I am trying to get readline support in python.
I am working on Linux and I have the latest version from svn. After I
./configure and make I can run python, but the readline support is not
there.
If I do:
%./configure >& out.txt
%grep readline out.txt
checking for readline in -lreadline...
Hi,
Isn't the following code supposed to return ('1994')?
>>> re.search('(\d{4})?', '4 1994').groups()
(None,)
Thanks,
Ray
--
http://mail.python.org/mailman/listinfo/python-list
20 matches
Mail list logo