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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:26:34+00:00 2026-06-11T10:26:34+00:00

Possible Duplicate: How do you split a list into evenly sized chunks in Python?

  • 0

Possible Duplicate:
How do you split a list into evenly sized chunks in Python?

Basically, I have a list, and I am iterating through every odd numbered index in the list. What I want to do, is based on the value of each odd numbered index, to then update a variable with the value in the even numbered index directly after said odd numbered index.

So if lst[1] contains the value p, then I want the value of x to be the value at lst[2]: x = lst[2].

If lst[3] contains the value m then I want y to be the value at lst[4]: y = lst[4]

The length of the list is never set in stone, since it grabs it from a file.

I am currently iterating through the list using this code:

for item in lst:
    if lst[range(1, len(lst), 2] == "p"
        x = ??

EDIT: I suppose to be more specific, I have created a class, and now am creating a function that will take information from a file, and use it to fill in the methods in my class. To do so I am reading in the file using readlines and then going through that list created by readlines and updating the methods in my class depending on what is in the file. Every odd line in the file is an indicator of which method I need to update with the line that comes directly after.

So:

if lst[1] == "p":
   s.methodOne(lst[2])
if lst[1] == "m":
    s.methodTwo(lst[2])

I’m just not sure how to grab what is in the even indexes after my odd ones.

My code is probably not very neat, but here is what I have so far:

def processScores(fname):
    infile = open(fname, 'r')
    lineinfo = infile.readlines()
    infile.close()
    lstinfo = []
    for item in lineinfo:
        lst = item.split(",")
        s = Score()
        s.initialize(lst[0])
        if lst[range(1, len(lst -1), 2] == "o" or "O":
  • 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-11T10:26:36+00:00Added an answer on June 11, 2026 at 10:26 am
    for idx in xrange(1, len(lst), 2):
        if lst[idx] == 'p':
            ...
        if lst[idx] == 'm':
            ...
    

    Note that the first element of lst is lst[0], so you are skipping it altogether here

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

Sidebar

Related Questions

Possible Duplicate: How do you split a list into evenly sized chunks in Python?
Possible Duplicate: How do you split a list into evenly sized chunks in Python?
Possible Duplicate: How do you split a list into evenly sized chunks in Python?
Possible Duplicate: How do you split a list into evenly sized chunks in Python?
Possible Duplicate: How do you split a list into evenly sized chunks in Python?
Possible Duplicate: Split array into chunks I am trying to convert an array of
Possible Duplicate: Split List into Sublists with LINQ Split a collection into n parts
Possible Duplicate: Split String into smaller Strings by length variable I have seen solutions
Possible Duplicate: How to split string into array as integers I have a 3x2
Possible Duplicate: How do i split a String into multiple values? I have 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.