473,391 Members | 1,522 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,391 software developers and data experts.

Rearranging letters

Hey

This is my first post here and i hope you can help :)
I would like to create a very basic easy program that can rearrange letters.
It would take the inputed word process it and print the new word out

for example if you entered the word job it would move each letter 3 spaces backwards so the printed result would be "gly"

What would be the best way to approach this

Thankyou in advance
Nov 29 '07 #1
3 8175
bvdet
2,851 Expert Mod 2GB
Hey

This is my first post here and i hope you can help :)
I would like to create a very basic easy program that can rearrange letters.
It would take the inputed word process it and print the new word out

for example if you entered the word job it would move each letter 3 spaces backwards so the printed result would be "gly"

What would be the best way to approach this

Thankyou in advance
Make a string of ascii letters:
Expand|Select|Wrap|Line Numbers
  1. >>> import string
  2. >>> string.ascii_lowercase
  3. 'abcdefghijklmnopqrstuvwxyz'
  4. >>> letters = string.ascii_lowercase
The string index of each letter can be found by using the string method index(). Subtract 3 from the index number, and get the new letter from the string using the slice operator.
Expand|Select|Wrap|Line Numbers
  1. >>> word = 'job'
  2. >>> ''.join([letters[letters.index(letter)-3] for letter in word])
  3. 'gly'
  4. >>> 
Nov 29 '07 #2
ghostdog74
511 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. >>> s="def"
  2. >>> ''.join([chr(ord(ch)-3) for ch in s])
  3. 'abc'
  4.  
Nov 29 '07 #3
That worked great thanks alot :)

I wrote it line by line into the python command line. Is there anyway to copy it out like into a text file and just change the word whenever i want menaing i don't have to repeatly write it out for just one word

thanks in advance

Edit: That was to the first reply. I will look at the second reply now

edit again: They both worked great. Now if i can only work out how to save it i will be sitting good :D
Nov 29 '07 #4

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

Similar topics

2
by: Edward K. Ream | last post by:
From the documentation for the string module at: C:\Python23\Doc\Python-Docs-2.3.1\lib\module-string.html letters: The concatenation of the strings lowercase and uppercase described below....
19
by: Johannes Nix | last post by:
Hello, yesterday I met a cute person (after my dance class) who told me about an interesting experiment regarding cognition. People were told to read a typed text; However, in every word in the...
1
by: Tor Inge Rislaa | last post by:
Rearranging the row position in a datagrid Hi I have a datagrid that I fill from a dataset. When the data is displayed in the grid I want the user to be able to move the position of a row. E.g....
7
by: stevenkobes | last post by:
A lot of websites have forms with an image at the bottom containing some distorted / noisy letters and numbers that users must type in to prove they are real people. How do they normally implement...
1
by: Kosmos | last post by:
Since people have been so helpful on this site I thought I'd contribute what little I can...since I am not a programmer but I'm working on an access database for work Anyways I had to remove...
4
by: db2admin | last post by:
Hello, I want to plan rearranging tables in our database according to business areas. say all tables in business area A will be in seperate tablespace or tablespaces. I am planning to monitor...
0
by: selvakumari | last post by:
hi, In my project in a treeview i am doing drag and drop function and after that modifying some values in a treeview ascending order of nodes, some times the treeview may contain 255 nodes each...
8
by: trixxnixon | last post by:
Could Rearranging columns on a table, effect other areas of the database such as reports and queries?
4
by: abueno | last post by:
//It should count how many characters are letters in the English alphabet, and is displaying the correct letters, but is not counting good. void FunctionCountLetters(char s) { int len; int i;...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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.