I am writing a program that changes ascii input to text. That itself is not hard. My problem is this, the format for the ascci input is rather weird.
42$28$50$65$79$62$77$37$56$
Now, I can put the string into a list, and have it ignore the special characters. However, It breaks up the numbers like this:
[4,2,2,8,5,0,6,5,7,9,6,2,7,7,3,7,5,6]
Is there a way to change the input string into a list that is formatted like this?:
[42,28,50,65,79,62,77,37,56]
In other words, keeping the original format, while ignoring the special characters.
3 1540 bvdet 2,851
Expert Mod 2GB
I am writing a program that changes ascii input to text. That itself is not hard. My problem is this, the format for the ascci input is rather weird.
42$28$50$65$79$62$77$37$56$
Now, I can put the string into a list, and have it ignore the special characters. However, It breaks up the numbers like this:
[4,2,2,8,5,0,6,5,7,9,6,2,7,7,3,7,5,6]
Is there a way to change the input string into a list that is formatted like this?:
[42,28,50,65,79,62,77,37,56]
In other words, keeping the original format, while ignoring the special characters.
- >>> s = '42$28$50$65$79$62$77$37$56$'
-
>>> s.split('$')
-
['42', '28', '50', '65', '79', '62', '77', '37', '56', '']
-
>>> s.strip('$').split('$')
-
['42', '28', '50', '65', '79', '62', '77', '37', '56']
-
>>> [i for i in s.split('$') if i]
-
['42', '28', '50', '65', '79', '62', '77', '37', '56']
-
>>>
- >>> s = '42$28$50$65$79$62$77$37$56$'
-
>>> s.split('$')
-
['42', '28', '50', '65', '79', '62', '77', '37', '56', '']
-
>>> s.strip('$').split('$')
-
['42', '28', '50', '65', '79', '62', '77', '37', '56']
-
>>> [i for i in s.split('$') if i]
-
['42', '28', '50', '65', '79', '62', '77', '37', '56']
-
>>>
Thanks, I actually figured it out right before reading this. Found a new problem lol.
Here is the code I am using: -
import os
-
import string
-
string = raw_input('Text to decode: ')
-
shift = raw_input('Shift is: ')
-
string = string.split('%')
-
string = string[0:-1]
-
shift = int(shift)
-
x = -1
-
x = int(x)
-
shift = shift * x
-
newlist = []
-
newlist2 = []
-
for each in string:
-
each = int(each)
-
each = each + shift
-
newlist.append(each)
-
for chara in newlist:
-
chara = chr(chara)
-
newlist2.append(chara)
-
print newlist2
-
This only works if '$' is used to separate the ascii.
I tried: - bad = string.letters + '_' + '-' + '[' + ']' + '{' + '}' + '"' + ':' + ';' + '<' + '>' + '?' + '/' + '!' + '@' + '#' + '$' + '%' + '^' + '&' + '*' + '(' + ')'
-
string = string.split(bad)
However, that didn't work. Is there away to remove everything except integers from the string?
I really do appreciate your help. Thank you.
bvdet 2,851
Expert Mod 2GB
Thanks, I actually figured it out right before reading this. Found a new problem lol.
Here is the code I am using: -
import os
-
import string
-
string = raw_input('Text to decode: ')
-
shift = raw_input('Shift is: ')
-
string = string.split('%')
-
string = string[0:-1]
-
shift = int(shift)
-
x = -1
-
x = int(x)
-
shift = shift * x
-
newlist = []
-
newlist2 = []
-
for each in string:
-
each = int(each)
-
each = each + shift
-
newlist.append(each)
-
for chara in newlist:
-
chara = chr(chara)
-
newlist2.append(chara)
-
print newlist2
-
This only works if '$' is used to separate the ascii.
I tried: - bad = string.letters + '_' + '-' + '[' + ']' + '{' + '}' + '"' + ':' + ';' + '<' + '>' + '?' + '/' + '!' + '@' + '#' + '$' + '%' + '^' + '&' + '*' + '(' + ')'
-
string = string.split(bad)
However, that didn't work. Is there away to remove everything except integers from the string?
I really do appreciate your help. Thank you.
Assuming you want to remove the non-digit characters from the string: - import re
-
import string
-
-
patt = re.compile(r'\d+')
-
-
s = '42$28$50$65$79$62$77$37$56$'
-
s1 = ''.join(patt.findall(s))
-
print '%s -----> %s' % (s, s1)
-
-
s2 = ''.join([i for i in s if i in string.digits])
-
print s2
Output: - >>> 42$28$50$65$79$62$77$37$56$ -----> 422850657962773756
-
422850657962773756
-
>>>
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brandon Hoppe |
last post by:
I'm trying to change the src of an ilayer in the parent document from a link inside the
ilayer. I'm not able to get it to work. All that happens is Netscape 4 crashes. This is
for Netscape 4 only....
|
by: Elizabeth Harmon |
last post by:
Hi All
I am attempting to open a Word App from a web page on the client and so far
everything
works (After reconfig of dcomcnfg for Microsoft Word Document). I have one
minor problem, i cannot...
|
by: Warren Sirota |
last post by:
Hi,
Please let me know if I am interpreting this correctly. I've done a
little testing of the difference between passing parameters byVal and
byRef, and the results were slightly non-intuitive,...
|
by: Siv |
last post by:
Hi,
If I run the following:
strSQL = "Select * FROM Clients;"
da = New OleDb.OleDbDataAdapter(strSQL, Conn) 'Create data adapter
cb = New OleDb.OleDbCommandBuilder(da) ...
|
by: Rahul |
last post by:
Hi Everybody
I have some problem in my script. please help me. This is script file.
I have one *.inq file. I want run this script in XML files. But this
script errors shows . If u want i am...
|
by: Mohan |
last post by:
In the database, we are storing time in 3 columns: hours, Minutes and
AM,PM.
After retrieving it from the database, I want to load these values into
a DateTime variable. I haven't had much...
|
by: sparks |
last post by:
I have 2 fields that I have to make sure don't get screwed up.
(could be one it doesn't matter)
but what they want is no duplicates, warn the user
changing existing numbers is a no no. (of course...
|
by: Jack Wu |
last post by:
Hi
I've spent a good majority of my day trying to figure out how to have
PIL 1.1.5 working on my OSX 10.3.9_PPC machine. I'm still stuck and I
have not gotten anywhere. Could somebody please...
|
by: yjh0914 |
last post by:
hi guys! so im basically editting my post i made earlier as it wznt as specific..
i have to make a program that basically ranks students by their cumulative gpa. the student's info is on a csv file...
|
by: Barry |
last post by:
I know this is not a php question. If that bothers you, don't respond. If
not, I sure could use the advice...
I'm using a very abbreviated set of code to show a calendar. The idea is to
simply...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |