Getting a unknown word out of a list with no spaces
Hello Lets say I have a string: --a href=/browse/brick--brick--/a-- The -- needs to be replaced with or where applicable. and I want the brick out of that string (the second brick that is). How can I get just the brick out of that string? -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18502758.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
Alexandr N Zamaraev wrote: s = '--a href=/browse/brick--brick--/a--' s '--a href=/browse/brick--brick--/a--' ''.join('%s' % l if i % 2 == 1 else l for i, l in enumerate(s.split('--'))) ' /browse/brick brick ' -- http://mail.python.org/mailman/listinfo/python-list I'm sorry, I don't think I was being clear. I replaced the 's with -- so it would post online w/o actually making a link. I just need to know how to get the brick out. -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18503144.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
Alexnb wrote: s = '--a href=/browse/brick--brick--/a--' s '--a href=/browse/brick--brick--/a--' ''.join('%s' % l if i % 2 == 1 else l for i, l in enumerate(s.split('--'))) ' /browse/brick brick ' I'm sorry, I don't think I was being clear. I replaced the 's with -- so it would post online w/o actually making a link. I just need to know how to get the brick out. 1) if string really '--a href=/browse/brick--brick--/a--' s.split('--', 3)[2] brick 2) if string 'a href=/browse/brickbrick/a' s.split('', 1)[1].split('')[0] brick -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
Alexandr N Zamaraev wrote: Alexnb wrote: s = '--a href=/browse/brick--brick--/a--' s '--a href=/browse/brick--brick--/a--' ''.join('%s' % l if i % 2 == 1 else l for i, l in enumerate(s.split('--'))) ' /browse/brick brick ' I'm sorry, I don't think I was being clear. I replaced the 's with -- so it would post online w/o actually making a link. I just need to know how to get the brick out. 1) if string really '--a href=/browse/brick--brick--/a--' s.split('--', 3)[2] brick 2) if string ' /browse/brick brick ' s.split('', 1)[1].split('')[0] brick -- http://mail.python.org/mailman/listinfo/python-list Excellent! it works. But I have one more question. How can I test to see if the first character of a string is what I want, for example, how can I test to see if the first char of a string is ? -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18503367.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
On Jul 17, 9:50 am, Alexnb: how can I test to see if the first char of a string is ? I suggest you to try the interactive shell: hello[0] 'h' hello[0] == False hello[0] == h True hello.startswith(h) True Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
bearophileHUGS wrote: On Jul 17, 9:50 am, Alexnb: how can I test to see if the first char of a string is ? I suggest you to try the interactive shell: hello[0] 'h' hello[0] == False hello[0] == h True hello.startswith(h) True Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list really? That's just like C. I thought that it would fail because of the way lists work. Thanks! -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18503830.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
Alexnb wrote: hello[0] 'h' hello[0] == False hello[0] == h True hello.startswith(h) True really? That's just like C. I thought that it would fail because of the way lists work. Thanks! what way? the first three will fail if the string is empty. [0] Traceback (most recent call last): File stdin, line 1, in module IndexError: string index out of range if you may end up doing this on an empty string, use slicing instead: hello[:1] == False [:1] == False (startswith is perhaps more convenient, but method calls are rather expensive in Python, so if you're in a hurry, it's often better to use operators. when in doubt, benchmark the alternatives.) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
BeautifulSoup. You need a good html parsing, not some one-shot code to handle one tiny unflexable pattern. On Thu, Jul 17, 2008 at 3:07 AM, Alexnb [EMAIL PROTECTED] wrote: Hello Lets say I have a string: --a href=/browse/brick--brick--/a-- The -- needs to be replaced with or where applicable. and I want the brick out of that string (the second brick that is). How can I get just the brick out of that string? -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18502758.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list