Re: [Tutor] how to unique the string

2011-10-24 Thread lina
On Mon, Oct 24, 2011 at 3:24 PM, Peter Otten <__pete...@web.de> wrote: > lina wrote: > >> But I am getting confused later: >> >> def translate_process(dictionary,tobetranslatedfile): >>     results=[] >>     unique={} >>     for line in open(tobetranslatedfile,"r"): >>         tobetranslatedparts=l

Re: [Tutor] how to unique the string

2011-10-24 Thread lina
>> >> def translate_process(dictionary,tobetranslatedfile): >>     results=[] >>     unique={} >>     for line in open(tobetranslatedfile,"r"): >>         tobetranslatedparts=line.strip().split() >>         results.append(dictionary[tobetranslatedparts[2]]) >>         unique=Counter(results) >>  

Re: [Tutor] how to unique the string

2011-10-24 Thread lina
On Mon, Oct 24, 2011 at 3:24 PM, Peter Otten <__pete...@web.de> wrote: > lina wrote: > >> But I am getting confused later: >> >> def translate_process(dictionary,tobetranslatedfile): >>     results=[] >>     unique={} >>     for line in open(tobetranslatedfile,"r"): >>         tobetranslatedparts=l

Re: [Tutor] how to unique the string

2011-10-24 Thread Peter Otten
lina wrote: > But I am getting confused later: > > def translate_process(dictionary,tobetranslatedfile): > results=[] > unique={} > for line in open(tobetranslatedfile,"r"): > tobetranslatedparts=line.strip().split() > results.append(dictionary[tobetranslatedparts[2]])

Re: [Tutor] how to unique the string

2011-10-23 Thread Dave Angel
On 10/23/2011 08:01 AM, lina wrote: On Sun, Oct 23, 2011 at 6:06 PM, Peter Otten<__pete...@web.de> wrote: lina wrote: tobetranslatedparts=line.strip().split() strip() is superfluous here, split() will take care of the stripping: " alpha \tbeta\n".split() ['alpha', 'beta'] for residue in

Re: [Tutor] how to unique the string

2011-10-23 Thread lina
On Sun, Oct 23, 2011 at 6:06 PM, Peter Otten <__pete...@web.de> wrote: > lina wrote: > tobetranslatedparts=line.strip().split() > > strip() is superfluous here, split() will take care of the stripping: > " alpha \tbeta\n".split() > ['alpha', 'beta'] > for residue in results:    

Re: [Tutor] how to unique the string

2011-10-23 Thread Peter Otten
lina wrote: >>> tobetranslatedparts=line.strip().split() strip() is superfluous here, split() will take care of the stripping: >>> " alpha \tbeta\n".split() ['alpha', 'beta'] >>> for residue in results: >>> if residue not in unique: >>> unique[residue]=1 >>> else: >>> un

Re: [Tutor] how to unique the string

2011-10-23 Thread lina
The updated one -- following Alan's advice. #!/usr/bin/python3 import os.path mapping={} DICTIONARYFILE="dictionary.pdb" TOBETRANSLATEDFILEEXT=".out" OUTPUTFILEEXT=".txt" def generate_dict(dictionarysourcefile): for line in open(dictionarysourcefile,"r"): parts=line.strip().split(

Re: [Tutor] how to unique the string

2011-10-23 Thread lina
On Sun, Oct 23, 2011 at 5:08 PM, Alan Gauld wrote: > On 23/10/11 09:33, lina wrote: > >> I have a further question: >> > >> Welcome anyone help me transform the code to another form. > > What form would you like it transformed to? > A flow chart? Another programming language? A different style of

Re: [Tutor] how to unique the string

2011-10-23 Thread Alan Gauld
On 23/10/11 09:33, lina wrote: I have a further question: > Welcome anyone help me transform the code to another form. What form would you like it transformed to? A flow chart? Another programming language? A different style of Python (Functional programming or OOP maybe?) I'm not sure wh

Re: [Tutor] how to unique the string

2011-10-23 Thread lina
On Sun, Oct 23, 2011 at 12:50 AM, Steven D'Aprano wrote: > lina wrote: >> >> Hi, >> >> I googled for a while, but failed to find the perfect answer, >> >> for a string >> >> ['85CUR', '85CUR'] > > > That's not a string, it is a list. > > >> how can I unique it as: >> >> ['85CUR'] > > Your question

Re: [Tutor] how to unique the string

2011-10-22 Thread lina
On 23 Oct, 2011, at 0:22, Devin Jeanpierre wrote: > You should be able to do this yourself, with the help of the following link: > > http://docs.python.org/library/stdtypes.html#set Thanks. > > Is this a homework question? No. > > Devin > > On Sat, Oct 22, 2011 at 12:09 PM, lina wrote: >

Re: [Tutor] how to unique the string

2011-10-22 Thread Steven D'Aprano
lina wrote: Hi, I googled for a while, but failed to find the perfect answer, for a string ['85CUR', '85CUR'] That's not a string, it is a list. how can I unique it as: ['85CUR'] Your question is unclear. If you have this: ['85CUR', '99bcd', '85CUR', '85CUR'] what do you expect to g

Re: [Tutor] how to unique the string

2011-10-22 Thread bob gailer
On 10/22/2011 12:09 PM, lina wrote: Hi, I googled for a while, but failed to find the perfect answer, for a string ['85CUR', '85CUR'] how can I unique it as: ['85CUR'] Try set(['85CUR', '85CUR'] -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tu

Re: [Tutor] how to unique the string

2011-10-22 Thread Devin Jeanpierre
You should be able to do this yourself, with the help of the following link: http://docs.python.org/library/stdtypes.html#set Is this a homework question? Devin On Sat, Oct 22, 2011 at 12:09 PM, lina wrote: > Hi, > > I googled for a while, but failed to find the perfect answer, > > for a strin