Python Forum
count occurrence of numbers in a sequence and return corresponding value
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
count occurrence of numbers in a sequence and return corresponding value
#3
(May-19-2019, 02:03 PM)ichabod801 Wrote: What have you tried?

I have tried something like below but I am stuck at how to return the corresponding value
X = [2,2,2,2,2,3,4,5,6,6,6,6,6,7,8]
Y = [4,4,4,4,4,0,0,0,5,5,5,5,5,0,0]
count_sequence = [sum(1 for _ in group) for _, group in groupby(X)]
print(count_sequence)
for i in count_sequence:
    if i>= 5:
        print(Y[i]) #not sure if this is correct
 
Reply


Messages In This Thread
RE: count occurrence of numbers in a sequence and return corresponding value - by python_newbie09 - May-19-2019, 06:43 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 16,271 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Row Count and coloumn count Yegor123 4 1,515 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  How to get unique entries in a list and the count of occurrence james2009 5 3,165 May-08-2022, 04:34 AM
Last Post: ndc85430
  Selecting the first occurrence of a duplicate knight2000 8 5,546 May-25-2021, 01:37 AM
Last Post: knight2000
  How can I found how many numbers are there in a Collatz Sequence that I found? cananb 2 2,676 Nov-23-2020, 05:15 PM
Last Post: cananb
  Checking for one or more occurrence in a list menator01 3 2,815 May-18-2020, 06:44 AM
Last Post: DPaul
  Return prime numbers from range krzyfigh 2 2,035 Apr-20-2020, 08:08 PM
Last Post: krzyfigh
  Define a range, return all numbers of range that are NOT in csv data KiNeMs 18 7,524 Jan-24-2020, 06:19 AM
Last Post: KiNeMs
  How to count and order numbers in a list rachyioli 2 2,687 Aug-21-2019, 10:51 AM
Last Post: perfringo
  Print Numbers starting at 1 vertically with separator for output numbers Pleiades 3 3,936 May-09-2019, 12:19 PM
Last Post: Pleiades

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020