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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:35:49+00:00 2026-06-03T03:35:49+00:00

after the for loop arrays gets the values from tmp1. How can i store

  • 0

after the for loop arrays gets the values from tmp1. How can i store values for later use?

def getCardRank(self, arrays, straight = False):
  print arrays

  tmp1 = arrays[:]  
  tmp2 = {i: arrays[i] for i in range(0, len(arrays))}

  print tmp1

  for array in tmp1:
    for card in array:
      i = array.index(card)
      mod = card % 13

      if (mod == 0 and False != straight):
        card = 0 if sum(array) == 27 else 13
      else:
        card = 13 if mod == 0 else mod
        array[i] = card

  print tmp1
  print tmp2

that gives me:

[[44, 43, 42, 41, 40], [37, 36, 35, 34, 33], [17, 16, 15, 14, 26]]

[[44, 43, 42, 41, 40], [37, 36, 35, 34, 33], [17, 16, 15, 14, 26]]

{0: [44, 43, 42, 41, 40], 1: [37, 36, 35, 34, 33], 2: [17, 16, 15, 14, 26]}

[[5, 4, 3, 2, 1], [11, 10, 9, 8, 7], [4, 3, 2, 1, 13]]

{0: [5, 4, 3, 2, 1], 1: [11, 10, 9, 8, 7], 2: [4, 3, 2, 1, 13]}
  • 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-03T03:35:51+00:00Added an answer on June 3, 2026 at 3:35 am

    I’m a little unclear on the question, but I’ll assume that you want print(tmp1) to always print [44, 43, 42]...etc instead of [5, 4, 3].

    The problem with the assignment tmp1 = arrays[:] is that if you create a copy of a list to iterate over using slice notation, the original list is changed.

    In order to store the original array in tmp1, a rather inefficient solution would be to create a tuple tmp1 and iterate over arrays appending each element to tmp1. Another would be, as previously suggested, to pickle your data structures.

    However, it looks like the real solution is to change how you’re thinking about storing tmp1 – consider that if you need to retain the original arrays after calling getCardRank, you probably want to think of it as part of the object that self refers to in the function’s signature. Therefore, you should store the original copy of arrays in a member variable (self.foo = [array for array in arrays]).

    As a side note, it makes your code somewhat more difficult to read when you use inline conditionals.

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

Sidebar

Related Questions

I'm at a loss why this loop stops after the first item. Can someone
So I have an array that gets created from a php loop that looks
I am downloading a lot of data in a loop but after some operations
My script is acting strange. After a foreach loop, the script stops. I don't
After trying to make a while(bool) loop and it failing because I couldn't see
I have a loop which basically calls this every few seconds (after the timeout):
I am trying to create a loop function based on the time. After the
I am developing a command line script which runs in an infinite loop. After
I wanted to add <br> after every 2 loops. The loop will run 8
In Matlab, I have a loop that performs operations on arrays. I would like

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.