Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Select single letters from string based on separate string
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.)
You are asking complicated things. Are you inventing a new encryption mechanism?
You may solve it in this way:
s1 = '085236752048'
print(''.join(s2[int(ch)] for ch in s1[6:11]))
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.
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.
Ibreeden, A couple of days ago I finally achieved a scanner readable label with win10,Spyder,Tkinter.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  regex match in a string batchen 3 115 5 hours ago
Last Post: snippsat
  Converting query string as a condition for filter data. shah_entrance 1 59 Jan-14-2020, 09:22 AM
Last Post: perfringo
  How to print the 2nd column of a searched string in a csv ptey07 2 100 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 96 Jan-08-2020, 08:02 AM
Last Post: perfringo
  Print string after decode martinzeifang 1 136 Jan-02-2020, 10:16 AM
Last Post: buran
  Replacing characters in a string with a list cjms981 1 142 Dec-30-2019, 10:50 PM
Last Post: micseydel
  splitting a string with 2 different delimiters Skaperen 4 246 Dec-30-2019, 04:49 AM
Last Post: BamBi25
  string literals in a list. Not what I expected. tycarac 3 158 Dec-28-2019, 05:31 AM
Last Post: tycarac
  Python convert multi line into single line formatted string karthidec 2 168 Dec-23-2019, 12:46 PM
Last Post: karthidec
  How to check if user entered string or integer or float?? prateek3 5 3,460 Dec-21-2019, 06:24 PM
Last Post: DreamingInsanity

Forum Jump:

Users browsing this thread: 1 Guest(s)