Python introductory study-output of sales data using tuples-

setting a goal

2020/0719 For study output using PyQ Keep a record of your own learning + aim for something that people in the same position can read.

In principle, be aware of the following in learning. ・ Do not just do the basics, but start creating simple applications and tools as soon as the basics are completed. ・ If you don't understand something, do a quick search, and if you don't understand it, proceed. ・ Be aware that programming is nothing more than a tool for making what you want to make. ・ Set goals clearly and study while being aware of the period.

Small goal End the PyQ curriculum. Now: Learn Containers

Big goal Create an application in Python.

Output of sales data using tuples

What is a tuple?

A tuple is a type of data that manages multiple elements such as lists and dictionaries.

・ Elements cannot be added / deleted / changed ・ () And, are trademarks ・ Memory used is smaller than the list * ・ In many cases, tuples can be calculated faster than lists * ・ Can be used with list and dictionary types -Data type can be changed with list () and tuple () functions

Problem: Please output data with customer ID of 10 or less and sales amount of 100 yen or more.

code """ sales = ((1, 100), (2, 30), (7, 150), (11, 120), (10, 100))

for sale in sales: if sale[0] <= 10 and sale[1] >= 100: print(sale)

"""

output """ (1, 100) (7, 150) (10, 100) """

Set method

A set is a list-like data structure, but with the following characteristics:

・ Literals use curly braces such as {'art','box'}. ・ Only immutable (immutable) items can be entered. ・ You can have only one of the same item. Even if you add more than one, it will be one. -There is no order. If acquired as iterable, the order may change each time it is executed. -There are operations between sets. -Searching is faster than the list.

Set method (addition / update / deletion)

add(item) Add an item.

update(iterable) Add all the elements of the iterable iterable.

clear() Delete all elements.

pop() Deletes any element and returns it.

remove(item) Delete the item. If item does not exist, an error (KeyError) will occur.

discard(item) Delete the item. No error will occur even if item does not exist.

""" items = {'art'} print("items:", items)

Delete 1 element

result = items.pop() print("items.pop():", result) print("items:", items)

Add list

items.update(["egg", "fog"]) print("items.update(['egg', 'fog'])") print("items:", items)

Delete all

items.clear() print("items.clear()") print("items:", items)

add to

items.add("doll") print("items.add('doll')") print("items:", items)

Delete

items.remove("doll") print("items.remove('doll')") print("items:", items) """

output

items: {'art'} items.pop(): art items: set() items.update(['egg', 'fog']) items: {'fog', 'egg'} items.clear() items: set() items.add('doll') items: {'doll'} items.remove('doll') items: set()

Recommended Posts

Python introductory study-output of sales data using tuples-
Data analysis using Python 0
Data cleaning using Python
[Python] [Word] [python-docx] Simple analysis of diff data using python
python: Basics of using scikit-learn ①
Data analysis using python pandas
[Python] I tried collecting data using the API of wikipedia
Image capture of firefox using python
Data acquisition using python googlemap api
Removal of haze using Python detailEnhanceFilter
Implementation of desktop notifications using Python
Recommendation of data analysis using MessagePack
Introductory table of contents for python3
Basic map information using Python Geotiff conversion of numerical elevation data
Python: Basics of image recognition using CNN
[Python] Extension using inheritance of matplotlib (NavigationToolbar2TK)
Automatic collection of stock prices using python
(Bad) practice of using this in Python
Python: Application of image recognition using CNN
Get Youtube data in Python using Youtube Data API
[Python] Various data processing using Numpy arrays
Recommendation of Altair! Data visualization with Python
Study on Tokyo Rent Using Python (3-1 of 3)
Creating Google Spreadsheet using Python / Google Data API
[Introduction to Data Scientists] Basics of Python ♬
Awareness of using Aurora Severless Data API
Meaning of using DI framework in Python
Time variation analysis of black holes using python
Chord recognition using chromagram of python library librosa
[Python] Get all comments using Youtube Data API
Real-time visualization of thermography AMG8833 data in Python
Introduction of Python Imaging Library (PIL) using HomeBrew
Character encoding when using csv module of python 2.7.3
[Python3] Let's analyze data using machine learning! (Regression)
The story of reading HSPICE data in Python
Try using the collections module (ChainMap) of python3
Anonymous upload of images using Imgur API (using Python)
Find the geometric mean of n! Using Python
A well-prepared record of data analysis in Python
[Data science memorandum] Handling of missing values ​​[python]
Check the status of your data using pandas_profiling
Python / Automatic low wrench unfitting of experimental data
Scraping the winning data of Numbers using Docker
Summary of Excel operations using OpenPyXL in Python
Summary of statistical data analysis methods using Python that can be used in business
I want to get custom data attributes of html as elements using Python Selenium
Data analysis python
Start using Python
Basics of Python ①
Basics of python ①
[In-Database Python Analysis Tutorial with SQL Server 2017] Step 4: Feature extraction of data using T-SQL
Copy of python
Scraping using Python
[python] Read data
Introduction of Python
Let's analyze Covid-19 (Corona) data using Python [For beginners]
[Python] Implementation of clustering using a mixed Gaussian model
Use data class for data storage of Python 3.7 or higher
Create a data collection bot in Python using Selenium
Summary of tools needed to analyze data in Python
Full-width and half-width processing of CSV data in Python