Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8525541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:00:38+00:00 2026-06-11T08:00:38+00:00

Couldn’t find an answer to this solution, so once I figured it out I

  • 0

Couldn’t find an answer to this solution, so once I figured it out I thought I’d re-post my solution…

I was looking for a way of taking a user input (sys.argv[1]) and use this value to perform a lookup in a CSV file for another value in column x (e.g. 5). This would be part of a larger script and I would use the looked-up value as a test.

My example csv would be:

col0,col1,col2,col3,col4
a,foo,bar,blah,1
b,foo,bar,blah,2
c,foo,bar,blah,3
d,foo,bar,blah,4
e,foo,bar,blah,5
f,foo,bar,blah,6
g,foo,bar,blah,7
h,foo,bar,blah,8
i,foo,bar,blah,9
j,foo,bar,blah,10
k,foo,bar,blah,11
l,foo,bar,blah,12
m,foo,bar,blah,13
n,foo,bar,blah,14
o,foo,bar,blah,15
p,foo,bar,blah,16
q,foo,bar,blah,17
r,foo,bar,blah,18
s,foo,bar,blah,19
t,foo,bar,blah,20
u,foo,bar,blah,21
v,foo,bar,blah,22
w,foo,bar,blah,23
x,foo,bar,blah,24
y,foo,bar,blah,25
z,foo,bar,blah,26
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T08:00:40+00:00Added an answer on June 11, 2026 at 8:00 am

    I had a quick look at your Javascript question, and if you’re only ever mapping char->position in alphabet, what about the following?

    def char_to_pos(char):
        from string import ascii_lowercase
        try:
            return ascii_lowercase.index(char) + 1
        except ValueError as e:
            pass # no match - do what's sensible here
    

    And if you wanted to pre-generate a lookup table, then something like:

    from string import ascii_lowercase
    from itertools import count
    
    lookup = dict(zip(ascii_lowercase, count(1)))
    # or depending on taste
    lookup = {letter: idx for idx, letter in enumerate(ascii_lowercase, start=1)}
    

    Otherwise, since CSV files are generally relativey small you could just load the entire file to RAM to avoid repeated sequential lookups later (as long as the CSVs not so large it’ll put your machine in a coma)

    with open('test1.csv') as fin:
        csvin = csv.reader(fin)
        lookup = {row[0]: row for row in csvin}
    
    to_find = 'x'
    try:
        print '{} = {[4]}'.format(to_find, lookup[to_find])
    except (KeyError, IndexError) as e:
        pass # KeyError = no lookup match, IndexError is that CSV file didn't have 5th column...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Couldn't find this anywhere, maybe I'm looking for the wrong verbs. I'm trying to
Couldn't find an answer to this question. It must be obvious, but still. I
I couldn't find the answer to this in any other question. Suppose that I
Couldn't seem to find the answer to this question - what is the haml
Couldn't find an answer to this one. I have a WPF ListView control that
Couldn't find any good information on how to do this so I thought I'd
Couldn't find an answer to this unfortunately so hoping someone can help. In Spring
Couldn't find any answer to this problem, or not even any questions asked. So
Couldn't comment on this post, which states the problem I'm experiencing: jQuery remove() on
I couldn't find anything similar to this anywhere. I have an array of pointers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.