473,395 Members | 1,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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-unkn...p18503367.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jul 17 '08 #1
3 1156
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
Jul 17 '08 #2

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-unkn...p18503830.html
Sent from the Python - python-list mailing list archive at Nabble.com.

Jul 17 '08 #3
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>

Jul 17 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

303
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b....
3
by: Adam | last post by:
How is best to extract word strings from a line = infile.readline() I wish to quickly check the first word of each line of a text file. Indeed, How do I break a lineinput() line into...
9
by: Steven Bethard | last post by:
I've got a list of word substrings (the "tokens") which I need to align to a string of text (the "sentence"). The sentence is basically the concatenation of the token list, with spaces sometimes...
7
by: onetitfemme | last post by:
Hi, for some reason Firefox is apparently inserting a new line somehow after some IPA symbols which I have written in their hexadecimal notation. Also, I would like to have two spaces by...
1
by: biznitchil | last post by:
it is a bit jacked up, but copy and paste it into an IDE(i use jGRASP) plz help me...it worked just fine before I added the menu..you can e-mail me if you have any <Removed> import java.util.*; ...
6
by: nagar | last post by:
I need to get the list of Autocorrect entries in word. Is there a way to do it without connecting to Word? Is the list saved somewhere? If I need to connect to Word, how can I detect if it's...
1
by: desivirus | last post by:
hi admin.. i followed your tip in "HOW TO LIST PROCESS ID IN WINDOWS" thread..and iam trying to compile this code in cygwin , $gcc -mno-cygwin process.c -o -L"psapi.lib" process.exe psapi.h...
11
by: arnuld | last post by:
C takes input character by character. I did not find any Standard Library function that can take a word as input. So I want to write one of my own to be used with "Self Referential Structures" of...
0
by: Alexnb | last post by:
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...
0
by: Alexnb | last post by:
Alexandr N Zamaraev wrote: 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"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.