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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:26:30+00:00 2026-06-12T11:26:30+00:00

I writing a script in python in which I am extracting some information from

  • 0

I writing a script in python in which I am extracting some information from some files and passing it into another file.

I have 2 dictionaries that contains lists of elements of a class, and I want to write each element of the list into a .csv file.

When I try to write the data to the file it appears in a weird way. I want the data to appear in this way:

Sample_3 45526536 7010285 31195850 7320401 45500691 7186449 31021951 7292291  
Sample_1 48885783 7715654 33474067 7696062 48857972 7907873 33282945 7667154

but instead I have this result:

 Sample_3 ['45526536'] ['7010285'] ['31195850'] ['7320401'] ['45500691'] ['7186449'] ['31021951'] ['7292291']
 Sample_1 ['48885783'] ['7715654'] ['33474067'] ['7696062'] ['48857972'] ['7907873'] ['33282945']['7667154']

Does anyone know why is adding [´´] to the numbers? I try to make an really simple method to eliminate the [‘ ‘] but then I won’t print anything in the file.

def correct_str(value):  
    new= str(value).strip("['")
    final= str(new).strip("']")
    return final

Here is the code here I am adding elements to the dictionary, the dictionary is a global variable called stat_dict_l_u, and the name is the key to the dictionary, in this case Sample_1 and Sample_2, and list values is a list that contains the numbers I got from a file. I believe that maybe my problem comes from the way I am adding the values to the dictionary.

def processNumbersLeft(name,list_values):

    list_reads=[]


    for value in list_values:
        print value.total_reads
        list_reads.append(value.total_reads)



    list_aligned_once=[]
    for value in list_values:

        n=re.split(" ",value.aligned_once)
                 list_aligned_once.append(n[0])


    list_failed=[]
    for value in list_values:

        n=re.split(" ",value.failed)
        list_failed.append(n[0])

    list_aligned_several=[]
    for value in list_values:

        n=re.split(" ",value.aligned_several)

        list_aligned_several.append(n[0])



    stat_elem=Statistics(list_reads,list_aligned_once,list_failed,list_aligned_several)

    stat_dict_l_u[name]=stat_elem

Thank you!

  • 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-12T11:26:31+00:00Added an answer on June 12, 2026 at 11:26 am

    Try to use this case:

    def to_file(d):
        return '\n'.join("%s %s" % (key, ' '.join(map(str, values))) for key, values in d.items())
    

    Using:

    >>> print to_file({'Sample_1': [1,2,3], 'Sample_2': [4,5,6]})
    Sample_1 1 2 3
    Sample_2 4 5 6
    

    Note, if you need to a lot of work with csv-file, use helpful module csv. Example of using:

    import csv
    with open('eggs.csv', 'wb') as csvfile:
        spamwriter = csv.writer(csvfile, delimiter=' ', quoting=csv.QUOTE_MINIMAL)
        for key, values in d.items():
            spamwriter.writerow([key] + values)
    

    This example does exactly what you need. For more information read documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a small Python script which will periodically pull information from a 3rd
I am writing a python script to import content from another CMS into Plone
Folks, I have a problem. I am a writing a script in python which
I am writing python script which gets links from website. But when I tried
I amm writing a little python script that will grab information from VMs of
I am writing a python script which looks at common computer files and examines
I am writing a Python script to do some admin functionality which involves running
I'm writing a Python script which processes a text file. I expect to process
I am writing a Python logger script which writes to a CSV file in
I have a python script that I am writing for a class assignment which

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.