Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Select single letters from string based on separate string
#1
I've done this in Excel using the =Lookup({}) function, but have no clue how to in Python. String 1 (12 digits): 085236752048. String 2 (10 letters): @ABCDEFGHI. I need to select 5 letters from string 2, based on the values of string 1 from the 7th-11th digit. In this case the result would be; GEB@D. I've tried slice(), but found that I can't index a slice. Thanks for any help. (this is not critical.)
Quote
#2
You are asking complicated things. Are you inventing a new encryption mechanism?
You may solve it in this way:
s1 = '085236752048'
s2 = '@ABCDEFGHI'
print(''.join(s2[int(ch)] for ch in s1[6:11]))
Output:
GEB@D
Explanation:
for ch in s1[6:11]: Walk through the numbers in string 1 (mind you: index starts at 0 and last index is not included)
s2[int(ch)]: make an integer of the character found in the loop and consider this as an index in string 2.
''.join(...): start with an empty string and join this successively with the characters found.
Quote
#3
I Breeden, Thank you very much. I have a font that is specific to UPCA. the bars are set for consecutive letters and a couple of symbols. The solution you provided gave me the necessary code to equate the two. I can now enter the 11 numbers and it will figure the check Digit, then it converts the entire 12 digits to the font readable text for a UPCA symbol. I added, with your code, the first number, the next 5 numbers, the separator, the last five (your code) and the check Digit. I've worked on this ever since since I coded a program in 1983 in Basic and QBasic. I moved on to Excel and then to Microsoft Access, both with macros in Visual Basic. The program won't produce a scanner readable UPCA symbol. Again my thanks.
Jim
Quote
#4
Ibreeden, A couple of days ago I finally achieved a scanner readable label with win10,Spyder,Tkinter.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Converting query string as a condition for filter data. shah_entrance 1 55 Jan-14-2020, 09:22 AM
Last Post: perfringo
  How to print the 2nd column of a searched string in a csv ptey07 2 94 Jan-11-2020, 11:25 AM
Last Post: ptey07
  I want to filter out words with one letter in a string (pig latin translator) po0te 1 91 Jan-08-2020, 08:02 AM
Last Post: perfringo
  Print string after decode martinzeifang 1 131 Jan-02-2020, 10:16 AM
Last Post: buran
  Replacing characters in a string with a list cjms981 1 140 Dec-30-2019, 10:50 PM
Last Post: micseydel
  splitting a string with 2 different delimiters Skaperen 4 243 Dec-30-2019, 04:49 AM
Last Post: BamBi25
  string literals in a list. Not what I expected. tycarac 3 156 Dec-28-2019, 05:31 AM
Last Post: tycarac
  Python convert multi line into single line formatted string karthidec 2 164 Dec-23-2019, 12:46 PM
Last Post: karthidec
  How to check if user entered string or integer or float?? prateek3 5 3,414 Dec-21-2019, 06:24 PM
Last Post: DreamingInsanity
  how to convert list to string after append !! evilcode1 3 153 Dec-16-2019, 09:50 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)