473,505 Members | 16,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

new to site and python

16 New Member
i dnt have much access to the internet so thats why i take long to reply sorry about that. strings are a big headache fro me so i dnt know if u could give any ideas of how to go about them e.g, if i had to write a program where u have to enter a phrase and then the program calculates and outputs the acronym derived from that phrase. all help appreaciated thanks

--------------------------------------------------------------------------------
Apr 21 '07 #1
1 897
dshimer
136 Recognized Expert New Member
Here are a couple of things to look at. You could take the phrase and separate it into a list of words using split()
Expand|Select|Wrap|Line Numbers
  1. >>> p='this is a phrase'
  2. >>> p.split()
  3. ['this', 'is', 'a', 'phrase']
Then you could use a for loop to pull out the first letter of each word. Remember that the first letter of a string has an index of 0, second is 1, etc.
Expand|Select|Wrap|Line Numbers
  1. >>> for w in p.split():
  2. ...     print w[0]
  3. ...     
  4. t
  5. i
  6. a
  7. p
In this example I just printed the letter, but you could build a new word out of it (lets use a for acronym)
Expand|Select|Wrap|Line Numbers
  1. >>> a=''
  2. >>> for w in p.split():
  3. ...     a=a+w[0]
  4. ... 
  5. >>> print a
  6. tiap
or if you wanted it all upper case
Expand|Select|Wrap|Line Numbers
  1. >>> print a.upper()
  2. TIAP
Some of these methods have been listed as deprecated in the python docs, which I don't study enough to know why. Could someone say where to look for the new methods, I understand that things like string.atof() became float() which makes sense to me. However I don't understand how to replace some of the others listed at http://docs.python.org/lib/node42.html. In this post I use string.upper(), what would be correct?
Apr 21 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
1515
by: ariza | last post by:
greetings. it seems that the attribute site.here, of the site module, has vanished in python 2.4. up until python 2.3, site.here seemed (to me at least) a convenient way to get the complete path to...
3
1414
by: enrio | last post by:
I recently installed python 2.4, and many installed software packages stopped working. Some things got working after I copied some files and directories from /usr/lib/python2.3/site-packages to...
2
5405
by: Peter Saffrey | last post by:
(apologies for starting a new thread - Google can't retrieve the other message for some reason) Yes, /usr/lib/python/site-packages is in sys.path. This series of commands should explain what I...
5
5229
by: TiNo | last post by:
Hi, I have installed python two days ago on a USB memory stick (I am on the move and have no laptop.) I am on windows computers, mostly XP, all the time. Now, after pluging it in to a...
1
1732
by: michael.buonomo | last post by:
We have been using the Google recommended python script for about a year. We recently realized that the script was not crawling our sites url's, but just our folders which reside on the server. The...
2
1679
by: Davy | last post by:
Hi all, I have Python 2.4 and 2.5 in my PC. And PythonWin is installed as IDE. When I tried to use site-packages "Numpy", I installed the both version (i.e. for 2.4 and 2.5). Python 2.4 and...
9
2082
by: pythonewbie | last post by:
Hi all, I am newbie in Python, my wish would be to create python applications for both Linux/Win32. I am stucked on creating a function to get the Python install directory (and site-packages...
2
1902
by: Fuzzyman | last post by:
A very odd error with Python 2.5 (both 2.5.1 and 2.5.2 from the official msi installers and running on Vista under Parallels on the Mac). 'import site' fails due to a string in sys.path that...
6
2104
by: Magdoll | last post by:
Hi, I know this is potentially off-topic, but because python is the language I'm most comfortable with and I've previously had experiences with plone, I'd as much advice as possible on this. I...
10
1438
by: defn noob | last post by:
i unzipped and put the folder in site-packages. when i run setup.py install nothing happens. when i do import pp from shell it complains it doesnt exist. isnt placing the folder in...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7103
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
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7478
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...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.