SlideShare uma empresa Scribd logo
1 de 9
PARALLEL ARRAYS IN PYTHON
Higher Computing Science
RUNNER EXAMPLE
• Consider a race with 24 runners
• Data stored for each runner:
• name (string)
• bib number (integer)
• elite (Boolean)
RUNNER EXAMPLE
• The data would look like:
etc.
Name Bib Number Elite
John McGrain 1014 False
Akila Sinha 1818 True
Steven Lowe 1374 True
Kyle McNaught 1450 False
RUNNER EXAMPLE
• We can store this data using three parallel arrays:
name[]
bib_number[]
elite[]
RUNNER EXAMPLE
• We can initialise the 3 parallel arrays in Python as follows:
name = ['' for x in range (24)]
bib_number = [0 for x in range (24)]
elite = [False for x in range (24)]
Note this will initialise:
• all names to empty string
• all bib_numbers to 0
• all elite values to False
RUNNER EXAMPLE
• We can set the value of individual array items as follows:
name[0] = ‘John McGrain’
bib_number[0] = 1014
elite[0] = False
RUNNER EXAMPLE
• We can set the value of individual array items as follows:
name[0] = ‘John McGrain’
bib_number[0] = 1014
elite[0] = False
name[1] = ‘Akila Sinha’
bib_number[1] = 1
elite[1] = True
RUNNER EXAMPLE
• In this example the values are being hard coded into the parallel arrays.
• It’s more likely we would either have the user input the values into the
program and then assign the parallel arrays
or
• Read the values from a file into the parallel arrays
RUNNER EXAMPLE
• Once the arrays have been initialised with values we can get details
about individual runners. For example, Kyle McNaught is the 4th runner
in the arrays so we can get his details using index 3:
print(name[3]) -> Kyle McNaught
print(bib_number[3]) -> 1450
print(elite[3]) -> False

Mais conteúdo relacionado

Mais procurados

Mais procurados (20)

Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Looping Statements and Control Statements in Python
Looping Statements and Control Statements in PythonLooping Statements and Control Statements in Python
Looping Statements and Control Statements in Python
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
SD & D Input Validation
SD & D Input ValidationSD & D Input Validation
SD & D Input Validation
 
C Structures and Unions
C Structures and UnionsC Structures and Unions
C Structures and Unions
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | EdurekaWhat is Multithreading In Python | Python Multithreading Tutorial | Edureka
What is Multithreading In Python | Python Multithreading Tutorial | Edureka
 
Array in C
Array in CArray in C
Array in C
 
Python If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | EdurekaPython If Else | If Else Statement In Python | Edureka
Python If Else | If Else Statement In Python | Edureka
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
Nested loops
Nested loopsNested loops
Nested loops
 
Python basic
Python basicPython basic
Python basic
 
Method overriding
Method overridingMethod overriding
Method overriding
 
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
USER DEFINE FUNCTIONS IN PYTHON[WITH PARAMETERS]
 
Data types in c++
Data types in c++Data types in c++
Data types in c++
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
User Defined Functions
User Defined FunctionsUser Defined Functions
User Defined Functions
 

Semelhante a Parallel arrays in python

Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
MrNikhilMohanShinde
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
moduledesign
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
irdginfo
 
Basics of matlab
Basics of matlabBasics of matlab
Basics of matlab
Anil Maurya
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
ShahinAhmed49
 

Semelhante a Parallel arrays in python (20)

Lec2&3 data structure
Lec2&3 data structureLec2&3 data structure
Lec2&3 data structure
 
Lec2
Lec2Lec2
Lec2
 
Records in Python
Records in PythonRecords in Python
Records in Python
 
Array , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptxArray , Structure and Basic Algorithms.pptx
Array , Structure and Basic Algorithms.pptx
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
 
Lecture 2 coding_principles
Lecture 2 coding_principlesLecture 2 coding_principles
Lecture 2 coding_principles
 
6 arrays injava
6 arrays injava6 arrays injava
6 arrays injava
 
ch03-parameters-objects.ppt
ch03-parameters-objects.pptch03-parameters-objects.ppt
ch03-parameters-objects.ppt
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
6nullables in c#
6nullables in c#6nullables in c#
6nullables in c#
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
Basics of matlab
Basics of matlabBasics of matlab
Basics of matlab
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
Lecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptxLecture_3.5-Array_Type Conversion_Math Class.pptx
Lecture_3.5-Array_Type Conversion_Math Class.pptx
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Python-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdfPython-for-Data-Analysis.pdf
Python-for-Data-Analysis.pdf
 
Arrays_and_Strings_in_C_Programming.pptx
Arrays_and_Strings_in_C_Programming.pptxArrays_and_Strings_in_C_Programming.pptx
Arrays_and_Strings_in_C_Programming.pptx
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Python for Data Analysis.pdf
Python for Data Analysis.pdfPython for Data Analysis.pdf
Python for Data Analysis.pdf
 

Mais de Forrester High School

Mais de Forrester High School (20)

Database Evaluation
Database EvaluationDatabase Evaluation
Database Evaluation
 
Testing SQL
Testing SQLTesting SQL
Testing SQL
 
SQL
SQLSQL
SQL
 
Database Query Design
Database Query DesignDatabase Query Design
Database Query Design
 
Data Dictionary
Data DictionaryData Dictionary
Data Dictionary
 
Compound Keys
Compound KeysCompound Keys
Compound Keys
 
Entity Occurrence Diagrams
Entity Occurrence DiagramsEntity Occurrence Diagrams
Entity Occurrence Diagrams
 
Entity Relationship Diagrams
Entity Relationship DiagramsEntity Relationship Diagrams
Entity Relationship Diagrams
 
Database Analysis
Database AnalysisDatabase Analysis
Database Analysis
 
Software Evaluation
Software EvaluationSoftware Evaluation
Software Evaluation
 
Python Predefined Functions
Python Predefined FunctionsPython Predefined Functions
Python Predefined Functions
 
Python Substrings
Python SubstringsPython Substrings
Python Substrings
 
Variable Scope
Variable ScopeVariable Scope
Variable Scope
 
SDD Predefined Functions
SDD Predefined FunctionsSDD Predefined Functions
SDD Predefined Functions
 
SDD Cconditional Loops
SDD Cconditional LoopsSDD Cconditional Loops
SDD Cconditional Loops
 
SDD Fixed Loops
SDD Fixed LoopsSDD Fixed Loops
SDD Fixed Loops
 
SDD Conditional Statements
SDD Conditional StatementsSDD Conditional Statements
SDD Conditional Statements
 
SD & D Arithmetic Operators
SD & D Arithmetic OperatorsSD & D Arithmetic Operators
SD & D Arithmetic Operators
 
N5 security precautions
N5 security precautionsN5 security precautions
N5 security precautions
 
N5 Code Efficiency
N5 Code EfficiencyN5 Code Efficiency
N5 Code Efficiency
 

Último

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Último (20)

Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 

Parallel arrays in python

  • 1. PARALLEL ARRAYS IN PYTHON Higher Computing Science
  • 2. RUNNER EXAMPLE • Consider a race with 24 runners • Data stored for each runner: • name (string) • bib number (integer) • elite (Boolean)
  • 3. RUNNER EXAMPLE • The data would look like: etc. Name Bib Number Elite John McGrain 1014 False Akila Sinha 1818 True Steven Lowe 1374 True Kyle McNaught 1450 False
  • 4. RUNNER EXAMPLE • We can store this data using three parallel arrays: name[] bib_number[] elite[]
  • 5. RUNNER EXAMPLE • We can initialise the 3 parallel arrays in Python as follows: name = ['' for x in range (24)] bib_number = [0 for x in range (24)] elite = [False for x in range (24)] Note this will initialise: • all names to empty string • all bib_numbers to 0 • all elite values to False
  • 6. RUNNER EXAMPLE • We can set the value of individual array items as follows: name[0] = ‘John McGrain’ bib_number[0] = 1014 elite[0] = False
  • 7. RUNNER EXAMPLE • We can set the value of individual array items as follows: name[0] = ‘John McGrain’ bib_number[0] = 1014 elite[0] = False name[1] = ‘Akila Sinha’ bib_number[1] = 1 elite[1] = True
  • 8. RUNNER EXAMPLE • In this example the values are being hard coded into the parallel arrays. • It’s more likely we would either have the user input the values into the program and then assign the parallel arrays or • Read the values from a file into the parallel arrays
  • 9. RUNNER EXAMPLE • Once the arrays have been initialised with values we can get details about individual runners. For example, Kyle McNaught is the 4th runner in the arrays so we can get his details using index 3: print(name[3]) -> Kyle McNaught print(bib_number[3]) -> 1450 print(elite[3]) -> False