Removing a list element that repeats itself -- Solved

  • Context: Python 
  • Thread starter Thread starter Arman777
  • Start date Start date
  • Tags Tags
    Element List
Click For Summary

Discussion Overview

The discussion revolves around the problem of removing repeated elements from an array, specifically focusing on identifying and eliminating a repeating sequence within the array. The context includes coding solutions and algorithmic approaches to achieve this task.

Discussion Character

  • Technical explanation
  • Homework-related

Main Points Raised

  • The initial problem involves an array where a specific sequence repeats, and the user seeks a method to remove the duplicate sequence without using the set() function.
  • One participant questions the clarity of the problem statement, specifically asking how long a sequence must be before it is considered for removal.
  • A participant claims to have solved the problem but does not provide details initially.
  • A request is made for the solution to be shared for the benefit of others.
  • A code snippet is provided that attempts to identify repeating patterns in the array, although the contributor notes that they did not write it themselves and received help.

Areas of Agreement / Disagreement

There is no consensus on the clarity of the problem statement, and while one participant claims to have solved the issue, the details of the solution are not fully articulated. The discussion remains somewhat unresolved regarding the criteria for identifying the repeating sequence.

Contextual Notes

The discussion lacks specific definitions regarding the length of sequences that trigger removal and does not clarify the conditions under which the provided code operates effectively.

Arman777
Insights Author
Gold Member
Messages
2,163
Reaction score
191
I have an array that looks like

A=[0,0,1,1,2,5,6,3,7,7,0,0,1,1,2,5,6,3,7,7]

since the "0,0,1,1,2,5,6,3,7,7" part reapeats itself I don't need the second part so for a given array it should give me

A=[0,0,1,1,2,5,6,3,7,7]

I can't use the set() function and I don't know what else I can use in this case.Is there a function which can do this operation ?

I tried to write a code but I couldnt
 
Technology news on Phys.org
Your problem statement seems ill defined. How long must the sequence be before you remove it? In your example, "0" is repeated 4 times.
 
  • Like
Likes   Reactions: FactChecker and jedishrfu
oh umm I solved it..but thanks
 
  • Like
Likes   Reactions: jedishrfu
@Arman777 Can you share your solution so others can benefit?
 
  • Like
Likes   Reactions: jedishrfu
jim mcnamara said:
@Arman777 Can you share your solution so others can benefit?
Python:
def check_repeat(l):
    for i in range(1,len(l)//2+1):
        pattern=l[:i]
        sub_lists=create_sublists(l, i, True)
        if all([x==pattern for x in sub_lists]):
            print("Found pattern {} with length {}".format(pattern, i))
            return patterndef create_sublists(l, n, only_full=False):
    sub_lists=[]
    for j in range(n, len(l),n):
        if only_full and len(l[j:j+n])<n:
            continue
        sub_lists.append(l[j:j+n])
    return sub_lists

but I didnt write it myself. Someone helped me
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 43 ·
2
Replies
43
Views
5K
  • · Replies 29 ·
Replies
29
Views
4K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 9 ·
Replies
9
Views
1K
  • · Replies 7 ·
Replies
7
Views
6K
  • · Replies 34 ·
2
Replies
34
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K