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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:34:28+00:00 2026-05-26T21:34:28+00:00

Working in python 2.7. I’m sure the code is a little unwieldy, but I’ll

  • 0

Working in python 2.7.

I’m sure the code is a little unwieldy, but I’ll try to explain it as simply as I can.

I have two lists:

T = [[1,0], [1,0], [0,5]]
S = [[1], [3], [2]]

I need to add the corresponding value from B to the end of the corresponding list in T, so using zip, I put them together.

I then calculate the result of the first value of each list subtracted from the third, and append that value using another zip function.

So when I run my function, the T variable now looks like [[1,0,1,0], [1,0,3,-2], [0,5,2,-2]].

I then have a series of if statements that if certain values are higher or lower than others, the list returns win, loss, or tie.

I would like to simulate the results of my function (starterTrans) multiple times. The problem is that when I use:

def MonteCarlo(T, S, x):
    for i in range(0, x):
        starterTrans(T, S)

For each simulation I am getting a different version of T. So the first time through the simulation T has the appropriate number of elements in each list (four), but after each run through, more and more variables are added.

I need a way to lock T to it’s original four variables no matter how many times I want to use it. And I’m struggling finding a way to do so. Any ideas?

I know my code is convoluted, but here it is if it helps anyone follow my attempt to describe my problem:

def starterTrans(team, starter):
    wins = 0
    losses = 0
    nd = 0
    random.shuffle(team)
    for t, s in zip(team, starter):
        t.extend(s)
    score_add(team, exit_score(team, starter))
    length = len(starter)
    for i in range(0, length):
        if team[i][4] > 0 and (team[i][1] > -team[i][4]) and team[i][2] >= 5:
            wins += 1
        elif team[i][4] < 0 and (team[i][1] <= -team[i][4]):
            losses += 1
        elif (team[i][4] <= 0 and team[i][1] >= -team[i][4]):
            nd += 1
    return wins, losses, nd

def score_add(team, exit_scores):
    for t, e in zip(team, exit_scores):
        t.append(e)
    return team

def exit_score(team, starter):
    exit_scores = []
    length = len(starter)
    for i in range(0, length):
        score = team[i][0]-team[i][3]
        exit_scores.append(score)
    return exit_scores

def MonteCarlo(team, starter, x):
    for i in range(0, x):
        starterTrans(team, starter)

Thanks for any help.

  • 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-26T21:34:29+00:00Added an answer on May 26, 2026 at 9:34 pm

    I think you just need to change this:

    def MonteCarlo(T, S, x):
        for i in range(0, x):
            starterTrans(T, S)
    

    to this:

    def MonteCarlo(T, S, x):
        for i in range(0, x):
            starterTrans(T[:], S)
    

    This will pass a copy of T to starterTrans(..) instead of the original list. If you’re editing the elements of T in starterTrans(..) this will not help. Here you would need a deep copy. Have a look here for the difference between shallow and deep copies: What is the difference between a deep copy and a shallow copy?.

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

Sidebar

Related Questions

Working in python 2.7. I have two lists (simplified to make explanation more clear):
Working in python 2.7. I have two lists (simplified to make explanations clearer). T
Working in Python 2.7. I have two different lists, A and B (simplified to
I have emacs and python working on OSX, but I'd like to get a
I'm working with python, but I have a basic understanding of packaging with C.
I have a working Python 2.6 code using matplotlib, and would like to get
I'm working with Python and threads by some time, but I still have a
Working with Python in Emacs if I want to add a try/except to a
I have recently been working with Python using Komodo Edit and other simpler editors
I need to have an at-home project now that I'm working on Python/Django at

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.