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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:07:19+00:00 2026-06-08T07:07:19+00:00

How to do read a .csv file with the following content $C=2$A=3$B=1$ Then create

  • 0

How to do read a .csv file with the following content

$C=2$A=3$B=1$

Then create a new .csv file with the same content but the $ changed into , and sorted alphabetically like the following:

A=3,B=1,C=2

Thank you!

Edit:

Here’s my following code. It ended up giving an extra comma at the beginning of the output.

input = csv.reader(open('inputfile.csv','r'), delimiter='$')
output = open('outputfile.csv','w')
try:
    writer = csv.writer(output)
    for column in input:
        writer.writerow(sorted(column))
        print (sorted(column))
finally:
    out.close()

Right now my input is:

$C=2$A=3$B=1$

and my output is:

,A=3,B=1,C=2

I want it to be:

A=3,B=1,C=2

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-08T07:07:21+00:00Added an answer on June 8, 2026 at 7:07 am
    with open('test.csv') as in_file, open('new.csv', 'w') as out_file:
        for line in csv.reader(in_file, delimiter='$'):
            out_file.write(','.join(sorted(line)[2:])+'\n')
    

    Basically what this does is:

    • open the input as in_file
    • open the output as out_file
    • initializes a CSV reader with $ as the delimiter using in_file as the input file
    • iterates through each row doing the following:
      • sort all of the elements (after parsing)
      • discard the first 2 (since they’ll always be empty strings due to the start/end delimiters on each line)
      • recombine those elements using , as the delimiter
      • write that out to the file with a trailing newline \n

    edit: fixed for the start/end $ symbols by removing the empty elements that get parsed out of the CSV (the [2:] bit)

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

Sidebar

Related Questions

I'm trying to read a csv file into R that has date values in
I am using the csv python package to read a csv file like this:
I'm using an OleDbConnection, OleDbCommand, and OleDbDataReader to read a CSV file into a
I've used streamreader to read in a .csv file, then i need to split
I can't create an utf-8 csv file in Python. I'm trying to read it's
I wanted to read excel file so i did following steps. First creating .csv
I want to read a CSV file's columns directly into variables. The result should
I have a csv file to read, but in one column there are some
I want to read .csv file in PHP and put its contents into the
I have the following code for doing a linear regression: data<-read.csv(File.csv,header=T) trans<-log(data) attach(trans) outdata<-summary(lm(Y~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.