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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:55:34+00:00 2026-05-13T08:55:34+00:00

I am new to python and would appreciate a little help. How does one

  • 0

I am new to python and would appreciate a little help.

How does one do the following:

  1. Having converted each line within a file to a nested list,
    e.g. [['line 1', 'a'], ['line 2','b']] how do I flatten the list so that each line is associated with a variable. Assume that the first member in each list, i.e. i[:][0], is known.

  2. Is it possible to associate more than one list with one variable, i.e. can x = [list1], [list2]?

  3. Having used a for loop on a list, how those one associate aspects of that list with a variable? See example below.

Example:

for i in list_1:
    if i[:][0] == 'm':
        i[2] = a
        i[3] = b
        i[4] = c

The above returns NameError, a, b, c, not defined. How does one define variables resulting from iterations in a for loop or loops in general?

Hope I was clear and succinct as I am perplexed!

Update:

To clarify:

I have a nested list, where each list within the nest holds strings. These strings are actually numbers. I wish to convert the strings to integers in order to perform arithmetic operations.

Example:

[['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]

Now, to convert each string to an integer, is abs() appropriate? How should this be implemented?

Also, to sum the third item of each list within the nest and assign the total to a variable? Should I define a function for this?

Any suggestions on how to deal with this are much appreciated!

Also, the earlier suggestions, made me realise that my thinking was creating the problem! 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-05-13T08:55:35+00:00Added an answer on May 13, 2026 at 8:55 am
    # Answer to question 1 - just use the built-in functionality of lists.
    #
    # There is no need to use variables when lists let you do so much more
    #   in a quick and organised fashion.
    lines = []
    for line in open_file:
       lines.append(line)
    

    Since Li0liQ already answered questions 2 and 3, I’d just like to add a recommendation regarding question 3. You really don’t need to make a copy of the list via i[:] since you’re just testing a value in the list.

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

Sidebar

Ask A Question

Stats

  • Questions 270k
  • Answers 270k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, it doesn't. All configuration must go into a single… May 13, 2026 at 1:26 pm
  • Editorial Team
    Editorial Team added an answer Added position:relative to the div's and all was well in… May 13, 2026 at 1:26 pm
  • Editorial Team
    Editorial Team added an answer Could you just put an anchor in at each of… May 13, 2026 at 1:26 pm

Related Questions

I wanted to know Python is suited for what kind of applications? I am
See updated input and output data at Edit-1. What I am trying to accomplish
I have a very basic problem. I am learning my first steps with python
I've been having a problem with making sorted lists from dictionaries. I have this
I am new to python and struggling to find how to control the amount

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.