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 8894767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:35:29+00:00 2026-06-14T23:35:29+00:00

my first time asking something here. I have a text file of names, 1

  • 0

my first time asking something here. I have a text file of names, 1 name per line, that i’m reading in to a list, and then duplicating that list twice, the first time to remove \n’s and a second time to lowercase the list. then I ask the user for a search term, and convert their input to lowercase, and then search the lowercase version of the list for that, then i get the index of the match, and use that to display the non-lowercase version of that list item back to the user (so they can type for example anivia and get back Anivia). This is working fine but I’m sure my code is pretty bad. What I would like to do is add specific abreviations for some of the names in the list file, and accept those abbreviations as input, but still display back the full name. For example, user enters “mumu” and it sees that the list has Amumu – mumu, to reference Amumu. How could I go about accepting that abreviation? Also other cases like mf for Miss Fortune or kha for Kha’Zix. I thought of maybe having a second file contain the list of abbreviations but that seems so wasteful and I’m sure theres a better way. Here is my bad code so far:

f = open("champions.txt") #open the file
list = f.readlines() #load each line into the list
#print list
list2 = [item.rstrip('\n') for item in list] #remove trailing newlines in copy list
list3 = [item.lower() for item in list2] #make it all lowercase

print "-------\n", list2 #print the list with no newlines just to check

print "which champ" #ask user for input
value = raw_input().lower() #get the input and make it lowercase
if value in list3: #check list for value and then print back a message using that index but from the non-lowercase list
    pos = list3.index(value)
    print "list contains", list2[pos]
else: #if the input doesn't match an item print an error message
    print "error"

ill put this all into some function in my main file once it’s working the way i need. Basically I want to change some of the lines in my text file to have valid alternate abreviations and be able to accept those in this and still display the full name back to the user. For example, one of the lines in my secondary text file that has the abbreviations has a line of:

Kog'Maw - kogmaw, kog, km

how can i simplify what I have and add that functionality? I’m not really sure where to start, I’m pretty new to python and programming in general. Thank you for any help you can provide, sorry for such a long post.

  • 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-14T23:35:30+00:00Added an answer on June 14, 2026 at 11:35 pm

    OK, here’s a revised answer that assumes there’s one file containing names and abbreviations as shown at the beginning of this.

    Essentially what it does is make a large lookup table that maps any abbreviation in the file plus the name itself in lowercase to the name at the beginning of each line.

    lookup = {}
    with open("champions.txt") as f:
        for line in f:
            line = line.rstrip().split('-', 1)
            if not line: continue # skip any blank lines
    
            name = line[0].strip()
            lookup[name.lower()] = name
            if len(line) == 2:  # any alternative names given?
                for item in line[1].split(','):
                    lookup[item.strip()] = name
    
    print 'lookup table:'
    for alt_name, real_name in sorted(lookup.items()):
        print '{}: {}'.format(alt_name, real_name)
    print
    
    while True:
        print "which champ (Enter to quit): "  # ask user for input
        value = raw_input().lower()  # get the input and make it lowercase
        if not value: break
    
        real_name = lookup.get(value)
        if real_name:
            print 'found:', value, '-->', real_name
        else:
            print 'error: no match for', value
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

this is my first time asking something here, so don't be too harsh on
It's my first time asking for help in here, my department (a Government), have
this is my first time asking a question here. I tried to be well
first time posting here so be gentle :) On my web pages I have
For the first time, I am asking a little bit of help over here
Well this is not the first time im asking these question here but I
This is the first time i'm asking a question here at stack overflow so
this is my first time asking a question here so I hope I am
I'm sorry that was my first time for asking question in stackoverflow. I just
this is my first time asking a question so bear with me. I am

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.