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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:09:02+00:00 2026-06-12T14:09:02+00:00

I promise I’ve tried searching, but every single question I find ends up having

  • 0

I promise I’ve tried searching, but every single question I find ends up having some criteria unstated or violated that makes the answer insufficient for me.

I’m sending a list to a Python script. That list will be stored somewhere, but I want to minimize writes (this is on a remote service and I get charged for each write).

listNew = ["some", "list", "sent", "in", "that", "may", "be", "different", "later", "some"]
listPrevious = ["some", "some", "list", "that", "was", "saved", "previously"]

(Please don’t get distracted by their being strings; my list actually contains ints.)

The simple, basic algorithm is to iterate both lists on an index-by-index basis. If the items are the same, I don’t need to write; boom, money saved. The data ultimately saved, however, should be listNew.

In other languages, I could directly reference elements by index.

for (int i = 0; i < listNew.length; i++) {
    // Have we exceeded the previous list's length? Time to just write data in.
    if (listPrevious[i] == null)
        listPrevious.append(listNew[i]);
        continue;

    if (listNew[i] != listPrevious[i])
        listPrevious[i] = listNew[i]
}

Unfortunately, what I’ve found in looping techniques and list methods doesn’t provide:

  1. the means to get elements by index without removing it (pop method), nor

  2. the means to get the index of an element by exact value and positioning, since I have duplicates (in the above code, using
    list.index(“some”) would return the first index in listPrevious
    though I’m actually looking at the last element in listNew), nor

  3. the means to iterate through my lists beyond the length of one of the lists (zip() doesn’t iterate beyond the length of the smaller list, it seems).

Any ideas on how I should handle this? One of those three criteria were always violated in some way when I searched through previous questions.

I’m trying to avoid a solution like the following, by the way, which is also among the marked solutions in other questions.

for newitem in listNew
    for olditem in listPrevious
        if newitem != olditem
            # save the newitem

That compares the element from listNew with every single element in listPrevious, which is inefficient. I just need to know if it matches at the same index in the other list.

——- By Comment Request

Input: 2 lists, listNew and listPrevious. Another example

  • listNew = [100, 500, 200, 200, 100, 50, 700]
  • listPrevious = [100, 500, 200, 400, 400, 50]

Output: listPrevious is now listNew without having to overwrite elements that were the same.

listPrevious = [100, 500, 200, 200, 100, 50, 700]

  • did not require writes: [100, 500, 200, _, , 50, __] <- 4 writes saved

  • did require writes : [_, , __, 200, 100, __, 700] <- 3 writes executed, not .length writes executed!

  • 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-12T14:09:04+00:00Added an answer on June 12, 2026 at 2:09 pm

    From you C code I have created the following. Hopefully it does what you want:

    for i in range(len(listNew)):
        # Have we exceeded the previous list's length? Time to just write data in.
        if i >= len(listPrevious):
            listPrevious.append(listNew[i])
            continue
    
        if listNew[i] != listPrevious[i]:
            listPrevious[i] = listNew[i]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First question on SO and it's a real RTM candidate. But I promise you
Kind of a newbie question here but I promise it is really hard to
Ok I promise I'll learn regular expressions tonight but right now I need a
You have to promise not to giggle, but my situation is following: Instead of
I can't find Job in 2.0. Have been replaced by Promise? Promise seems a
Last question for tonight, I promise. These pointers are giving me a serious headache.
Ok, last question for today I promise! I have the following line of code
I'm having an issue with Jquery deferred object. I'm creating a promise inside a
This is long but I promise it's interesting. :) I'm trying to mimic the
Note to readers : Bear with me. I promise there's a question. I have

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.