Quick Lists Question (Count Occurences) - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Quick Lists Question (Count Occurences) (/thread-951.html) |
Quick Lists Question (Count Occurences) - EwH006 - Nov-16-2016 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! RE: Quick Lists Question (Count Occurences) - Larz60+ - Nov-16-2016 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 againDon't put that in a loop RE: Quick Lists Question (Count Occurences) - EwH006 - Nov-16-2016 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. RE: Quick Lists Question (Count Occurences) - metulburr - Nov-16-2016 (Nov-16-2016, 12:17 AM)Larz60+ Wrote: if len(mn) <> 9):You should use != <> is old python, and doesnt work in python3.x RE: Quick Lists Question (Count Occurences) - nilamo - Nov-16-2016 (Nov-16-2016, 12:28 AM)metulburr Wrote:Per PEP 401, that syntax is valid as of 3.1, as long as you(Nov-16-2016, 12:17 AM)Larz60+ Wrote: if len(mn) <> 9):You should use != from __future__ import barry_as_FLUFL ...and don't mind April fools modules... RE: python use of <> - metulburr - Nov-16-2016 i copied this thread to split the talk of <> into a new thread. RE: python use of <> - Skaperen - Nov-16-2016 does anyone here use 3.1? does anyone over there use 3.1? RE: python use of <> - Larz60+ - Nov-16-2016 Sorry old habit RE: python use of <> - nilamo - Nov-16-2016 (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 RE: python use of <> - Larz60+ - Nov-16-2016 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. |