Python Forum
Quick Lists Question (Count Occurences)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Quick Lists Question (Count Occurences)
#1
Good Evening,

I'm stuck in a headache and am looking to get some solutions. I've been given a problem that wants me to input 9 integers, and list the occurrences of those 9 integers. I've done it one way but the tool our class uses called 'Livelab' doesn't accept the code I gave it. For this purpose I will show both source code.


For the rejected code I used: 

from collections import Counter
a = [2, 5, 6, 5, 4, 3, 23, 43, 2]
print(Counter(a))
The code I'm working on currently looks like this. I've got some of the print statements to work within Idle, but am having trouble and the book I have has been little help.


for i in range(9):
   num_list = int(input("Enter integers between 1 and 100: "))
print(num_list.count(2))
print(num_list.count(5))
print(num_list.count(6))
print(num_list.count(4))
print(num_list.count(3))
print(num_list.count(23))
print(num_list.count(43))
Any help would be appreciated!
Reply
#2
On the numbers:
input all nine with one input statement:
my_numbers = input('Enter 9 numbers separated by spaces')
mn = my_numbers.split(' ')
if len(mn) <> 9):
    # Show error Do it again
Don't put that in a loop
Reply
#3
That isn't in python 3, or at least my interpret is saying it isn't. I'm talking about the <>.

I messed with that code a little bit though. That's not what I'm looking to do. I'm looking to input 9 numbers and after that count how many times each number occurs within that list.
Reply
#4
(Nov-16-2016, 12:17 AM)Larz60+ Wrote: if len(mn) <> 9):
You should use !=

<> is old python, and doesnt work in python3.x
Recommended Tutorials:
Reply
#5
(Nov-16-2016, 12:28 AM)metulburr Wrote:
(Nov-16-2016, 12:17 AM)Larz60+ Wrote: if len(mn) <> 9):
You should use !=

<> is old python, and doesnt work in python3.x
Per PEP 401, that syntax is valid as of 3.1, as long as you 
from __future__ import barry_as_FLUFL


...and don't mind April fools modules...
Reply
#6
i copied this thread to split the talk of <> into a new thread.
Recommended Tutorials:
Reply
#7
does anyone here use 3.1? does anyone over there use 3.1?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#8
Sorry old habit
Reply
#9
(Nov-16-2016, 03:01 AM)Skaperen Wrote: does anyone here use 3.1?  does anyone over there use 3.1?

I use 3.5.2.
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:01:18) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import barry_as_FLUFL
>>> True != False
  File "<stdin>", line 1
    True != False
          ^
SyntaxError: invalid syntax
>>> True <> False
True
Reply
#10
Actually the snippet of code that I used it in, was never tested, I wrote it on the fly.
I used <> because it's something I did for years while programming in C and C++
I also use python 3.5.2, and may have been using it without thinking.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Row Count and coloumn count Yegor123 4 1,342 Oct-18-2022, 03:52 AM
Last Post: Yegor123
  Quick question/help regarding my variable Extra 5 1,551 May-06-2022, 12:01 AM
Last Post: Extra
  Quick Question about Dictionaries Extra 6 1,834 Apr-29-2022, 08:34 PM
Last Post: Extra
  Filtering a data frame according to number of occurences of an observation Menthix 1 1,890 May-31-2021, 10:50 PM
Last Post: supuflounder
  Noob question about lists adifrank 4 2,895 Nov-19-2020, 03:26 AM
Last Post: adifrank
  beginner question about lists and functions sudonym3 5 2,774 Oct-17-2020, 12:31 AM
Last Post: perfringo
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,387 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  quick question/excel+python zarize 1 2,269 Dec-06-2019, 05:38 PM
Last Post: Larz60+
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,293 Mar-20-2019, 08:01 PM
Last Post: stillsen
  A quick question teczone 4 3,091 Sep-06-2018, 03:44 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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