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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:55:16+00:00 2026-06-01T10:55:16+00:00

Really simple question here but bugging me for long enough to ask. Code looks

  • 0

Really simple question here but bugging me for long enough to ask. Code looks like this:

f4 = open("genomekey2.txt", 'rb')
keyline = f4.readline()
keygenomes = []
for keyline in f4:
   keygenomes.append(keyline[:-1])

the genomekey2.txt file format looks like this

['Prochlorococcus marinus str. MIT 9202']
['Prochlorococcus marinus str. NATL1A']
['Synechococcus sp. RS9917']
['Nostoc sp. PCC 7120']
['Synechococcus sp. JA-2-3B'a(2-13)']

The problem being when I print the genomekey list it has all of the entries I want but with quotation marks around each of the [ ] found within the list. I want to get rid of the quotation marks so I can compare it with another list but so far haven’t found a way. I tried…

for a in keygenomes:
    a.replace('"', '')

But that didn’t seem to work. I would rather a solution where it just doesn’t add the quotation marks on at all. What are they for anyway and which part of the code (.append, .readline()) is responsible for adding them? Massively beginner question here but you guys seem pretty nice.

Edit: I eventually want to compare it with a list which is formatted as such

[[‘Arthrospira maxima CS-328’], [‘Prochlorococcus marinus str. MIT 9301’], [‘Synechococcus sp. CC9605’], [‘Synechococcus sp. WH 5701’], [‘Synechococcus sp. CB0205’], [‘Prochlorococcus marinus str. MIT 9313’], [‘Synechococcus sp. JA-3-3Ab’], [‘Trichodesmium erythraeum IMS101’], [‘Synechococcus sp. PCC 7335’], [‘Trichodesmium erythraeum IMS101’], …

Edit: So I think I got something to work with a combination of answers, thank you all for your help! The quotations were interfering with the list comparison so I just added them on to the first list as well, even though I think it’s only mimicking the list being entered as a string (of which I now think I understand the distinction) it seems to work

f4 = open("genomekey2.txt", 'rb')
keyline = f4.readline()
keygenomes = []
for keyline in f4:
    keygenomes.append(keyline[:-1])

specieslist = " ".join(["%s" % el for el in specieslist])

nonconservedlist = [i for i in keygenomes if i not in specieslist]

Edit: Yeah the above worked but the more elegant solution I found here (http://forums.devshed.com/python-programming-11/convert-string-to-list-71857.html) after understanding the problem better thanks to your guys help is like this:

for keyline in f4:
    keyline = eval(keyline)
    keygenomes.append(keyline)

Thanks!

  • 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-01T10:55:18+00:00Added an answer on June 1, 2026 at 10:55 am

    Based on what you want to compare your list to, it seems like you are wanting a list of lists and not a list of strings…. Maybe this?

    f4 = open("genomekey2.txt", 'rb')
    keygenomes = []
    for keyline in f4.readlines():
        if keyline:
            keygenomes.append(eval(keyline.strip()))
    

    You are going to have issues with lines line this:

    ['Synechococcus sp. JA-2-3B'a(2-13)']
    

    The quotes are not correct and it will break the eval. Is it possible to mix the quotes? Like this instead…

    ["Synechococcus sp. JA-2-3B'a(2-13)"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This sounds like a really simple question, but I am new to PHP. If
This maybe a really simple question but for some reason my code isn't working.
I feel like the answer to this question is really simple, but I really
This one may seem like a simple question, but it's really got me scratching
This is a really simple question, but I can't seem to find the answer.
This is probably a really simple question but one I've never quite worked out
I know this is a really simple question but my google-fu is failing me.
This is a pretty simple question really, but let's say I'm creating a model
This is a really simple question but I havn't done c++ properly for years
I would like to ask a really simple question. I am just passing a

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.