[Baypiggies] string to list question
Andrew Toulouse
andrew at atoulou.se
Thu Aug 5 06:54:46 CEST 2010
Hm. Other people had the idea of using regexes, and theirs looks better. D'oh. Ignore me.
On Aug 4, 2010, at 9:52 PM, Andrew Toulouse wrote:
> Looks like you're trying to turn it into a bunch of tokens. I'm assuming you have an arbitrarily long string.
>
> You could loop through each character in the input, append it to the stack, determine whether the stack is a valid token, and output it (and reset the stack if so). In pseudocode:
>
> def tokenizer(z):
> def isValid(characterList):
> return true if characterList is ['A'], ['T','/','G'], or ['C'] #this is pseudocode
>
> stack = []
> for character in z:
> stack.append(character)
> if (isValid(stack)):
> yield ''.join(stack)
>
> print(list(tokenizer("AT/CG")))
>
> Disclaimer: This is absolutely not super-optimal and is untested (and my Python is rusty, I've been doing almost all Java and Objective-C lately) but it should get the job done if you just need something quick, I think.
>
> On Aug 4, 2010, at 9:43 PM, Brian Rue wrote:
>
>> Naive solution:
>>
>> zlist = [z[0], z[1:4], z[4]]
>>
>> On Wed, Aug 4, 2010 at 9:37 PM, Vikram K <kpguy1975 at gmail.com> wrote:
>> Suppose i have this string:
>> z = 'AT/CG'
>>
>> How do i get this list:
>>
>> zlist = ['A','T/C','G']
>>
>>
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>>
>> _______________________________________________
>> Baypiggies mailing list
>> Baypiggies at python.org
>> To change your subscription options or unsubscribe:
>> http://mail.python.org/mailman/listinfo/baypiggies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/baypiggies/attachments/20100804/e2a42599/attachment-0001.html>
More information about the Baypiggies
mailing list