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

  • Home
  • SEARCH
  • 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 8521565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:51:50+00:00 2026-06-11T06:51:50+00:00

This is driving me crazy. I have a script that pulls data from a

  • 0

This is driving me crazy. I have a script that pulls data from a csv. For each row it makes it a list. The reason is I want to merge two items based on a command line argument.

Here is my list as an example:

row = ['city', 'state', 'zip', 'zippostal', 'company']

Well I know if I do a join on row[0] and row[2] I will get

row = ['citystatezip', 'zippostal', 'company']

Well what if I wanted this….

row = ['companycityzip', 'state', 'zippostal']

How could I do this?

Edit:

Im sorry I didnt mean to be brief. What I have is a csv file with a bunch of data sometimes the city state and zip is in different fields but I need to merge them either by a , or – depends on what is needed. So what I did was make them into a list and based on command line arguements selecting what columns they are in I need them to merge so Ex.

column a column b column c column d ……
city state zip code

I need to merge column a into b by a “,”. Well that works fine but sometimes column f will be the city and column a will be the state. So how to I merge them in a list and have both values end up in column a but still return the rest of the row minus the updated vaule.

  • 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-11T06:51:52+00:00Added an answer on June 11, 2026 at 6:51 am

    Maybe something like this?:

    >>> row = ['city', 'state', 'zip', 'zippostal', 'company']
    >>> joins = [[4, 0, 2], [1], [3]]
    >>> [''.join(row[i] for i in indices) for indices in joins]
    ['companycityzip', 'state', 'zippostal']
    

    As a function:

    def custom_join(row, *joins):
        return [''.join(row[i] for i in indices) for indices in joins]
    

    Examples:

    >>> row = ['city', 'state', 'zip', 'zippostal', 'company']
    >>> custom_join(row, [0, 1, 2], [3], [4])
    ['citystatezip', 'zippostal', 'company']
    >>> custom_join(row, [-1, 0, 2], [1], [-2])
    ['companycityzip', 'state', 'zippostal']
    

    Edit: Here is a version that will return the remainder of the list after performing the joins:

    def custom_join2(row, *joins):
        result = [''.join(row[i] for i in indices) for indices in joins]
        seen = set(i if i >= 0 else len(row)+i for indices in joins for i in indices)
        result.extend(v for i, v in enumerate(row) if i not in seen)
        return result
    
    >>> custom_join2(row, [-1, 0, 2])
    ['companycityzip', 'state', 'zippostal']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy. I have a PHP script that gets some data
Ok, this is driving me crazy. I have a CA that needs to know
This is driving me crazy. I have a library I source from multiple scripts,
This is driving me crazy. I have Python 2.5 and MySQL-python-1.2.3 from the .exe
This is driving me crazy. I have a very simple user control: public int?
This is driving me crazy and I can't find the answer anywhere. I have
This has been driving me crazy for the past few minutes I have a
This has been driving me crazy. I think I have everything in place but
Any regex gurus around here? its driving me crazy. Say I have this string:
This has been driving me crazy for 2 days. I have been trying to

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.