Bottom Page

Thread Rating:
• 0 Vote(s) - 0 Average
• 1
• 2
• 3
• 4
• 5
 Select single letters from string based on separate string Jpen10 Programmer named Tim Posts: 10 Threads: 3 Joined: Dec 2019 Reputation: 0 Likes received: 0 #1 Dec-10-2019, 03:10 PM 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.) ibreeden Splitter Posts: 180 Threads: 0 Joined: Aug 2019 Reputation: 25 Likes received: 26 #2 Dec-10-2019, 07:55 PM 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. Jpen10 Programmer named Tim Posts: 10 Threads: 3 Joined: Dec 2019 Reputation: 0 Likes received: 0 #3 Dec-11-2019, 01:04 AM 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 Jpen10 Programmer named Tim Posts: 10 Threads: 3 Joined: Dec 2019 Reputation: 0 Likes received: 0 #4 Dec-15-2019, 01:21 PM Ibreeden, A couple of days ago I finally achieved a scanner readable label with win10,Spyder,Tkinter. « Next Oldest | Next Newest »

Top Page

 Possibly Related Threads... Thread Author Replies Views Last Post Extracting year from a string using strptime and datetime builtin Drone4four 1 69 Yesterday, 04:11 PM Last Post: bowlofred String Comparing Harshil 15 303 Aug-05-2020, 05:50 PM Last Post: Harshil string problem Mathisdlg 6 364 Aug-05-2020, 09:31 AM Last Post: Mathisdlg Converting string to hex triplet menator01 4 150 Aug-03-2020, 01:00 PM Last Post: deanhystad extract a dictionary from a string berc 4 285 Jul-30-2020, 06:58 AM Last Post: berc string match Kristenl2784 1 128 Jul-28-2020, 03:14 PM Last Post: Kristenl2784 ValueError: could not convert string to float: RandomCoder 3 298 Jul-27-2020, 07:38 AM Last Post: ndc85430 Function parameters and values as string infobound 1 140 Jul-24-2020, 04:28 AM Last Post: scidam Reverse a String ragav_in 3 148 Jul-24-2020, 02:24 AM Last Post: ragav_in Print a certain string only the first time it appears in a test file buttercup 5 191 Jul-23-2020, 01:30 PM Last Post: palladium

Forum Jump:

Users browsing this thread: 1 Guest(s)