0% found this document useful (0 votes)
57 views

Data Structures and Algorithms-1

The document contains a list of 10 student names and their registration numbers enrolled in a course with code HDSC107 taught by Mr. Ruwa. It also contains a question asking to demonstrate 4 string processing algorithms in Python code and diagrams. The response provides examples and diagrams of common string processing algorithms in Python - stripping whitespace, splitting strings, joining list elements into a string, reversing a string, converting case, and replacing substrings.

Uploaded by

Gerald Kapingura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Data Structures and Algorithms-1

The document contains a list of 10 student names and their registration numbers enrolled in a course with code HDSC107 taught by Mr. Ruwa. It also contains a question asking to demonstrate 4 string processing algorithms in Python code and diagrams. The response provides examples and diagrams of common string processing algorithms in Python - stripping whitespace, splitting strings, joining list elements into a string, reversing a string, converting case, and replacing substrings.

Uploaded by

Gerald Kapingura
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

UNIVERSITY OF ZIMBABWE

NAME REG NUMBER:

RYAN T TSIKADA R2111435

TANAKA K MUNDICHA R215899D

SELBY CHIPUNZA R215897A

TAKUNDA M GATAKATA R219042J

ALLAN S ABRAHAM R219039R

CATHERINE MUGUNZVA R219041R

SOLOMON ALIDI R219031W

TAVONGA SIBANDA R219029G

TSEPO SIBANDA R215934C

CUTHBERT TONGOGARA R215918Y

COURSE CODE : HDSC107

LECTURER : MR RUWA
GROUP 22

Qn) Use Python code and diagrams to demonstrate how any 4


string processing algorithms work ? 

A string is an array of characters, either as a literal constant or as some kind of variable. The
latter may allow its elements to be mutated and the length changed and it may be fixed (after
creation). A string is generally considered as a data type and is often implemented as an array
data structure of bytes (or words) that stores a sequence of elements, typically characters,
using some character encoding. String may also denote more general arrays or other sequence
(or list) data types and structures.

Depending on the programming language and precise data type used, a variable declared to
be a string may either cause storage in memory to be statically allocated for a predetermined
maximum length or employ dynamic allocation to allow it to hold a variable number of
elements. When a string appears literally in source code, it is known as a string literal or an
anonymous string.

When working with strings there two tools which are very important which are String
processing and String manipulation. When you want to search for a certain expression in a
string, add multiple strings one has to be familiar with the concepts of string processing.
String processing is the Data Manipulation refers to the process of changing and organising
information to make it more organised and readable.
1. Stripping Whitespace
 

Stripping whitespace is an elementary string processing requirement. You can strip leading

whitespace with the lstrip() function (starting from the left side) and you can string the

trailing whitespace with the rstrip() function (starting from the right side) and to strip both

the leading and the trailing strip the strip() function is used.

Stripping Whitespace Code

  
Diagram representation of string strip() method functionality in python.
 
 2. Splitting Strings

 
Splitting strings into lists of smaller substrings is often useful and easily
accomplished in Python with the split() function

 
2. Joining List Elements Into a String

You can join list element strings into a single string in Python using the
join(.) function

Joining list elements with “and” other than whitespace in between


Str=”Ryan”,”and”,”Tanaka”

(‘ ’.join(s))

Ryan and Tanaka

 
4. Reversing a String
 
Python does not have a built-in string reverse method. However, given that
strings can be sliced like lists, reversing one can be done in the same succinct
fashion that a list's elements can be reversed.

 
PYTHON

.format (s[;;-1]))

NOHTYP

6. Replacing Substrings

 
To replace substrings, use the Python replace() string function
 

5. Converting Uppercase and Lowercase


 
Converting between cases can be done with the upper(), lower(), and
swapcase() funtions.

You might also like