Returns the number of times item appears in aList. You cannot make any assumptions about the contents of the list. You are not allowed to use any count methods from the Python library.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In python 

two possible ways please

# Counting Occurrences of an Item in a List

This function calculates the number of times a specified item appears in a given list. It does not utilize any built-in count methods from the Python library, and no assumptions are made about the contents of the list.

## Input Parameters

- **list aList**: A list containing elements of any type.
- **item many**: An object of any type whose occurrences in the list are to be counted.

## Output

- **int**: The number of times the specified item appears in the list.

## Example Usage

1. **Example 1: Count occurrences of `1`**

   ```python
   >>> get_count([1, 4, 3.5, '1', 3.5, 9, 1, 4, 2], 1)
   ```
   **Output**: `2`

   In this example, the number `1` appears two times in the list.

2. **Example 2: Count occurrences of `3.5`**

   ```python
   >>> get_count([1, 4, 3.5, '1', 3.5, 9, 4, 2], 3.5)
   ```
   **Output**: `2`

   The floating-point number `3.5` appears twice in the list.

3. **Example 3: Count occurrences of `9`**

   ```python
   >>> get_count([1, 4, 3.5, '1', 3.5, 9, 4, 2], 9)
   ```
   **Output**: `1`

   The number `9` appears once in the list.

4. **Example 4: Count occurrences of `'a'`**

   ```python
   >>> get_count([1, 4, 3.5, '1', 3.5, 9, 4, 2], 'a')
   ```
   **Output**: `0`

   The character `'a'` does not appear in the list at all.
Transcribed Image Text:# Counting Occurrences of an Item in a List This function calculates the number of times a specified item appears in a given list. It does not utilize any built-in count methods from the Python library, and no assumptions are made about the contents of the list. ## Input Parameters - **list aList**: A list containing elements of any type. - **item many**: An object of any type whose occurrences in the list are to be counted. ## Output - **int**: The number of times the specified item appears in the list. ## Example Usage 1. **Example 1: Count occurrences of `1`** ```python >>> get_count([1, 4, 3.5, '1', 3.5, 9, 1, 4, 2], 1) ``` **Output**: `2` In this example, the number `1` appears two times in the list. 2. **Example 2: Count occurrences of `3.5`** ```python >>> get_count([1, 4, 3.5, '1', 3.5, 9, 4, 2], 3.5) ``` **Output**: `2` The floating-point number `3.5` appears twice in the list. 3. **Example 3: Count occurrences of `9`** ```python >>> get_count([1, 4, 3.5, '1', 3.5, 9, 4, 2], 9) ``` **Output**: `1` The number `9` appears once in the list. 4. **Example 4: Count occurrences of `'a'`** ```python >>> get_count([1, 4, 3.5, '1', 3.5, 9, 4, 2], 'a') ``` **Output**: `0` The character `'a'` does not appear in the list at all.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education