The document discusses Python programming concepts like conditional statements, loops, lists and PyCharm IDE. It explains how to install Python and PyCharm on Windows. Key Python concepts covered include while, for and nested loops, if-else and elif conditional statements. The document also demonstrates various list operations in Python like accessing list items, finding length of a list, adding and removing items from a list.
Program slicing and testing in software engineering.
- It summarized static slicing and dynamic slicing
- Also, it summarized white and black box testing
Computer Network notes (handwritten) UNIT 1NANDINI SHARMA
Introduction of computer network, layered architecture, topology, guided and unguided media, signals, multiplexing, OSI vs TCP/IP , IP address, TCP , UDP, DHCP, DNS, HTTP, etc.
A chatbot is Artificial Intelligence (AI) software that can simulate a conversation (or a chat)
with a user in natural language through messaging applications, websites, and mobile apps or through
the telephone.
It is often described as one of the most advanced and promising expressions of interaction
between humans and machines. However, from a technological point of view, a chatbot only
represents the natural evolution of a Question Answering system leveraging Natural Language
Processing (NLP). Formulating responses to questions in natural language is one of the most typical
Examples of Natural Language Processing applied in various enterprises’ end-use applications.
Chatbot applications streamline interactions between people and services, enhancing customer
experience. At the same time, they offer companies new opportunities to improve the customers
engagement process and operational efficiency by reducing the typical cost of customer service.
To be successful, a chatbot solution should be able to effectively perform both of these tasks. Human
support plays a key role here: Regardless of the kind of approach and the platform, human
intervention is crucial in configuring, training and optimizing the chatbot system.
Fake news has a negative impact on individuals and society, hence the detection of fake news is becoming a bigger field of interest for data scientists. Attempts to leverage artificial intelligence technologies particularly machine/deep learning techniques and natural language processing (NLP) to automatically detect fake news and prevent its viral spread have recently been actively discussed.
Large technology companies have begun to take steps to address this trend. For example, Google has adjusted its news rankings to prioritize well-known sites and has banned sites with a history of spreading fake news. Facebook has integrated fact checking organizations into its platform.
This SlideShare explores the concept of NLP for detecting fake news in brief.
Department of Computer Application- Features of C language
Features of C language
Character set of C language
Variables
Rules for constructing variable names
Data types in C language
Variable declaration
Python is a high-level, object-oriented, interpreted programming language, which has garnered worldwide attention. Stack Overflow found out that 38.8% of its users mainly use Python for their projects. According to the website’s survey, Python’s popularity surpassed that of C# in 2018 – just like it surpassed PHP in 2017. On the GitHub platform, Python surpassed Java as the second-most used programming language, with 40% more pull requests opened in 2017 than in 2016. This makes Python certification one of the most sought-after programming certifications.
Program slicing and testing in software engineering.
- It summarized static slicing and dynamic slicing
- Also, it summarized white and black box testing
Computer Network notes (handwritten) UNIT 1NANDINI SHARMA
Introduction of computer network, layered architecture, topology, guided and unguided media, signals, multiplexing, OSI vs TCP/IP , IP address, TCP , UDP, DHCP, DNS, HTTP, etc.
A chatbot is Artificial Intelligence (AI) software that can simulate a conversation (or a chat)
with a user in natural language through messaging applications, websites, and mobile apps or through
the telephone.
It is often described as one of the most advanced and promising expressions of interaction
between humans and machines. However, from a technological point of view, a chatbot only
represents the natural evolution of a Question Answering system leveraging Natural Language
Processing (NLP). Formulating responses to questions in natural language is one of the most typical
Examples of Natural Language Processing applied in various enterprises’ end-use applications.
Chatbot applications streamline interactions between people and services, enhancing customer
experience. At the same time, they offer companies new opportunities to improve the customers
engagement process and operational efficiency by reducing the typical cost of customer service.
To be successful, a chatbot solution should be able to effectively perform both of these tasks. Human
support plays a key role here: Regardless of the kind of approach and the platform, human
intervention is crucial in configuring, training and optimizing the chatbot system.
Fake news has a negative impact on individuals and society, hence the detection of fake news is becoming a bigger field of interest for data scientists. Attempts to leverage artificial intelligence technologies particularly machine/deep learning techniques and natural language processing (NLP) to automatically detect fake news and prevent its viral spread have recently been actively discussed.
Large technology companies have begun to take steps to address this trend. For example, Google has adjusted its news rankings to prioritize well-known sites and has banned sites with a history of spreading fake news. Facebook has integrated fact checking organizations into its platform.
This SlideShare explores the concept of NLP for detecting fake news in brief.
Department of Computer Application- Features of C language
Features of C language
Character set of C language
Variables
Rules for constructing variable names
Data types in C language
Variable declaration
Python is a high-level, object-oriented, interpreted programming language, which has garnered worldwide attention. Stack Overflow found out that 38.8% of its users mainly use Python for their projects. According to the website’s survey, Python’s popularity surpassed that of C# in 2018 – just like it surpassed PHP in 2017. On the GitHub platform, Python surpassed Java as the second-most used programming language, with 40% more pull requests opened in 2017 than in 2016. This makes Python certification one of the most sought-after programming certifications.
Python Basics: A Complete Introduction to Python3.Your Complete Python Curriculum— With Exercises, Interactive Quizzeresources, and Sample python programs.Python for beginners to excel in their careers in programming
How to setup Pycharm environment for Odoo 17.pptxCeline George
Setting up a development environment for odoo using pycharm is highly preferred by odoo developers to develop and debug odoo modules and other related functionalities .
The PIC Microcontroller is an electronic device that is easy-to-use in both hardware and software. Sensing the environment by receiving inputs from many sensors, PIC Microcontroller affects its surroundings by controlling lights, motors, and a number of other accessories. It's intended for anyone making interactive hardware projects by connecting it with a power source, few leds and resistors.
This course is designed to introduce the PIC Microcontroller hardware and programming environment to get you started on building projects as soon as possible.
Unleash Your Inner Hero With this Course
-PIC Microcontroller Inner structure and Programming Introduction
-Leds, Resistors and Pushbuttons
-LCD Screens and Seven Segment Displays
-Motor and Keypad.
-DIY Projects and Quick Tips
A Tool for Creating Any Device Imaginable become a favorite of electronic Students and anyone interested in Device manufacturing because of their ease of use and extremely low cost.
Example projects include Ardupilot, a UAV platform able to control aerial drones.
Contents and Overview This course is designed for anyone interested in learning electronic design. No experience is required, and all you need is PIC Microcontroller and several low cost components.
With hours of content in many lectures, this course will take you from zero experience in electronics or programming to PIC Microcontroller Master.
Limited time offer
50% off
Join Today:https://goo.gl/WQIFNY
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
The Internet of Things (IoT) is a revolutionary concept that connects everyday objects and devices to the internet, enabling them to communicate, collect, and exchange data. Imagine a world where your refrigerator notifies you when you’re running low on groceries, or streetlights adjust their brightness based on traffic patterns – that’s the power of IoT. In essence, IoT transforms ordinary objects into smart, interconnected devices, creating a network of endless possibilities.
Here is a blog on the role of electrical and electronics engineers in IOT. Let's dig in!!!!
For more such content visit: https://nttftrg.com/
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSveerababupersonal22
It consists of cw radar and fmcw radar ,range measurement,if amplifier and fmcw altimeterThe CW radar operates using continuous wave transmission, while the FMCW radar employs frequency-modulated continuous wave technology. Range measurement is a crucial aspect of radar systems, providing information about the distance to a target. The IF amplifier plays a key role in signal processing, amplifying intermediate frequency signals for further analysis. The FMCW altimeter utilizes frequency-modulated continuous wave technology to accurately measure altitude above a reference point.
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Understanding Inductive Bias in Machine LearningSUTEJAS
This presentation explores the concept of inductive bias in machine learning. It explains how algorithms come with built-in assumptions and preferences that guide the learning process. You'll learn about the different types of inductive bias and how they can impact the performance and generalizability of machine learning models.
The presentation also covers the positive and negative aspects of inductive bias, along with strategies for mitigating potential drawbacks. We'll explore examples of how bias manifests in algorithms like neural networks and decision trees.
By understanding inductive bias, you can gain valuable insights into how machine learning models work and make informed decisions when building and deploying them.
DESIGN AND ANALYSIS OF A CAR SHOWROOM USING E TABS
Lab (1) installation of python
1. Department of Electrical Engineering
The University of Faisalabad
LAB No: 01
Title:
Introduction to PyCharm.
Objective:
How to download and install IDLE Python and PyCharm.
Codes and results demonstrating the use of conditional statements, loops, lists,
dictionaries etc.
Introduction:
Python is a widely used high-level programming language first launched in 1991. Since then,
Python has been gaining popularity and is considered as one of the most popular and flexible
server-side programming languages.
It isusedfor:
web development (server-side)
software development
mathematics
system scripting.
What can Python do?
Python can be used on a server to create web applications.
Python can be used alongside software to create workflows.
Python can connect to database systems. It can also read and modify files.
Python can be used to handle big data and perform complex mathematics.
Python can be used for rapid prototyping or for production-ready software
development.
Why Python?
Python works on different platforms (Windows, Mac, Linux, Raspberry Pi etc).
Python has a simple syntax similar to the English language.
Python has syntax that allows developers to write programs with fewer lines than some
other programming languages.
Python runs on an interpreter system meaning that code can be executed as soon as it is
written. This means that prototyping can be very quick.
Python can be treated in a procedural way an object-oriented way or a functional way.
Python Syntax compared to otherprogramming languages:
Python was designed for readability, and has some similarities to the English language
with influence from mathematics.
Python uses new lines to complete a command as opposed to other programming
languages which often use semicolons or parentheses.
2. Department of Electrical Engineering
The University of Faisalabad
Python relies on indentation, using whitespace, to define scope; such as the scope of
loops functions and classes. Other programming languages often use curly-brackets for
this purpose.
Download the Python:
Step_1:
Select the version of to install the Python. Python is available from its website, Python.org.
Once there, hover your mouse over the download menu, then over the Windows option, and
then click the button to download the latest release in the fig 1.1.
Figure 1.1
We select the Add Python 3.9 to PATH and then click on Customize installation.
3. Department of Electrical Engineering
The University of Faisalabad
Figure 1.2
Thenclickon Next.
Figure 1.3
4. Department of Electrical Engineering
The University of Faisalabad
Clickon Install forall usersfromthe Advanced Option and then click on Install.
Figure 1.4
Then click on install option. Now installation has been started in fig.1.5.
figure 1.5
And then close the installation. We can see that our setup was successful.
5. Department of Electrical Engineering
The University of Faisalabad
Figure 1.6
Verification of our installation on Command Prompt. We can see our installation is
complete.
Figure 1.7
Interface with the Python Window. Run a print program in fig. 1.8.
Figure 1.8
IntroductiontoPyCharm:
6. Department of Electrical Engineering
The University of Faisalabad
PyCharm is the most popular IDE used for Python scripting language. This chapter will give you
an introduction to PyCharm and explains its features.
PyCharm offers some of the best features to its users and developers in the following aspects:
Code completion and inspection
Advanced debugging
Support for web programming and frameworks such as Django and Flask.
Features of PyCharm:
Besides, a developer will find PyCharm comfortable to work with because of the features
mentioned below:
Code Completion:
PyCharm enables smoother code completion whether it is for built in or for an external
package.
SQLAlchemy as Debugger:
You can set a breakpoint, pause in the debugger and can see the SQL representation of the user
expression for SQL Language code.
Git Visualization in Editor:
When coding in Python, queries are normal for a developer. You can check the last commit
easily in PyCharm as it has the blue sections that can define the difference between the last
commit and the current one.
Code Coverage in Editor:
You can run .py files outside PyCharm Editor as well marking it as code coverage details
elsewhere in the project tree, in the summary section etc.
Package Management:
All the installedpackagesare displayedwithpropervisual representation.Thisincludeslist of installed
packagesand the abilitytosearchand add new packages.
Steps Involved:
You will have tofollowthe stepsgivenbelowtoinstall PyCharmonyoursystem.These stepsshow the
installationprocedure startingfromdownloadingthe PyCharmpackage fromitsofficialwebsite to
creatinga newproject.
Step1:
Download the required package or executable from the official website of PyCharm
https://www.jetbrains.com/pycharm/download/#section=windows. Here you will observe two
versions of package for Windows as shown fig 1.9 given below:
7. Department of Electrical Engineering
The University of Faisalabad
Figure 1.9
Note that the professional package involves all the advanced features and comes with free trial
for few days and the user has to buy a licensed key for activation beyond the trial period.
Community package is for free and can be downloaded and installed as and when required. It
includes all the basic features needed for installation. Note that we will continue with
community package throughout this tutorial.
Here we can see, we have two options in fig.1.10.
PyCharm Professional Edition PyCharm Community Edition
8. Department of Electrical Engineering
The University of Faisalabad
Figure 1.11
Click on Next to continue.
Figure 1.12
Step_2:
9. Department of Electrical Engineering
The University of Faisalabad
Download the community package (executable file) onto your systemand mention a
destination folder as shown below:
Click on all the options and then on Next.
Figure 1.13
Step3:
Now, begin the installation procedure similar to any other software package.
10. Department of Electrical Engineering
The University of Faisalabad
Figure 1.14
Our Installation is started.
Figure 1.15
11. Department of Electrical Engineering
The University of Faisalabad
Step4:
Once the installation is successful as shown in fig.1.16, PyCharm asks you to import settings of
the existing package if any.
Figure 1.16
User Interface of PyCharm
Editor The user interface of PyCharm editor is shown in the screenshot given below. Observe
that the editor includes various features to create a new project or import from an existing
project.
12. Department of Electrical Engineering
The University of Faisalabad
Figure 1.17 1
PyCharm – Understanding Basics:
This chapter will discuss the basics of PyCharm and make you feel comfortable to begin working
in PyCharm editor.
When you launch PyCharm for the first time, you can see in fig. 1.18 welcome screen with
entry points to IDE such as:
Creating or opening the project
Checking out the project from version control
Viewing the documentation
Configuring the IDE
Recall that in the last chapter, we created a project named demo1 and we will be referring to
the same project throughout this tutorial. Now we will start creating new files in the same
project to understand the basics of PyCharm Editor.
13. Department of Electrical Engineering
The University of Faisalabad
Figure 1.18
You can see in fig.1.19 snapshot describes the project overview of demo1 and the options to
create a new file. Let us create a new file called main.py.
Figure 1.19
Task #2:
Python WHILELoop:
Python While loop is a control statement that accepts a condition as the input. As long the
condition is True, loop-block statements are executed for each iteration of loop-counter. If you
forget to increment or decrement the counter, you will end up with an infinite loop.
Any infinite loop consumes more RAM (Random Access Memory) and crashes the PC.
The condition of a WHILE loop should yield a Boolean value like True or False. The condition
may contain a number of sub-conditions separated by Boolean operators.
Syntax:
14. Department of Electrical Engineering
The University of Faisalabad
while condition:
statement1;
statement2;
#end of while
Example:
#program to print numbers 1-10
c=1 #loop counter
while c<=10:
print(c, end=' ')
c = c+1 #incrementing counter
We execute the code the in fig 1.20.
Figure 1.20
Run a program andgive outputinfig.1.21.
Figure 1.21
Python WHILEwith BREAK:
Sometimes, it is necessary to come out of a loop based on certain conditions. Hence a BREAK
statement is used in Python to break the While loop (or even FOR loop or any loop).
Once the Python runtime encounters this BREAK statement, the control goes to the first
statement after the While-loop. All the statements below the break statement and within the
While-block are not executed (ignored). A Python Break statement is usually kept inside an IF or
ELSE block.
Syntax:
while condition:
statement1;
break
statement2;
15. Department of Electrical Engineering
The University of Faisalabad
#end of while
Example:
The below program prints Even numbers up to 20 using a WHILE and BREAK control
statements.
We execute the code the in fig 1.22.
Figure 1.22
Run a program and give output in fig. 1.23.
Figure 1.23
Python WHILEwith CONTINUE:
The Python CONTINUE statement is the reverse of the BREAK statement. When the Python
runtime encounters this CONTINUE statement, the control goes back to the beginning of the
loop. So, you should increment or decrement the loop-counter before writing any CONTINUE
statement to avoid infinite loops.
Remember that the Continue statement does not stop or halt the loop. It just instructs to
continue with the next iteration.
Syntax:
while condition:
statement1;
continue;
statement2
#endof while
We execute the code the in fig 1.24.
16. Department of Electrical Engineering
The University of Faisalabad
Figure 1.24
Run a program and give output in fig. 1.25.
Figure 1.25
Else-statements:
An else statement can be combined with an if statement. An else statement contains a block of
code that executes if the conditional expression in the if statement resolves to 0 or a FALSE
value.
The else statement is an optional statement and there could be at the most only
one else statement following if.
Syntax:
The syntax of the if...else statement is −
if expression:
statement(s)
else:
statement(s)
We execute the code the infig3.7.
17. Department of Electrical Engineering
The University of Faisalabad
Figure 1.26
Run a program and give output in fig. 1.27.
Output:
In the above example, discount is calculated on the input amount. Rate of discount is 5%, if the
amount is less than 1000, and 10% if it is above 10000. When the above code is executed, it
produces the following result.
The elif Statement:
The elif statement allows you to check multiple expressions for TRUE and execute a block of
code as soon as one of the conditions evaluates to TRUE.
Similar to the else, the elif statement is optional. However, unlike else, for which there can be
at the most one statement, there can be an arbitrary number of elif statements following an if.
Syntax
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Core Python does not provide switch or case statements as in other languages, but we can use
if..elif...statements to simulate switch case as follows
18. Department of Electrical Engineering
The University of Faisalabad
We execute the code the infig3.9.
Figure 3.9
Run a program and give output in fig. 1.28.
Figure 1.28
Python conditional statemnts (Task 3):
Introduction:
Decision-making is as important in any programming language as it is in life. Decision-making in
a programming language is automated using conditional statements, in which Python evaluates
the code to see if it meets the specified conditions.
The conditions are evaluated and processed as true or false. If this is found to be true, the
program is run as needed. If the condition is found to be false, the statement following the If
condition is executed.
Python has the following conditional statements that are used in decision-making:-
1. If the statement
2. If else statement
3. Nested if statement
4. Switch statement
What is Python If Statement?
19. Department of Electrical Engineering
The University of Faisalabad
Python if Statement is used for decision-making operations. It contains a body of code which
runs only when the condition given in the if statement is true. If the condition is false, then the
optional else statement runs which contains some code for the else condition.
When you want to justify one condition while the other condition is not true, then you use
Python if else statement.
Python if Statement Syntax:
if expression
Statement
else
Statement
Example 1:
def main():
x,y =2,8
if(x < y):
st= "x is less than y"
print(st)
if __name__ == "__main__":
main()
What happen when “if condition” does not meet?
In this step, we will see what happens when if condition in Python does not meet.
def main():
x,y=8,2
if(x < y):
st= "x isless thany"
print(st)
if __name__ == "__main__":
main()
20. Department of Electrical Engineering
The University of Faisalabad
How to use “else condition”:
The “else condition” is usually used when you have to judge one statement on the basis of
other. If one condition goes wrong, then there should be another condition that should justify
the statement or logic.
Example:
def main():
x, y = 8, 4
if (x < y):
st = "x is less than y"
else:
st = "x is greater than y"
print(st)
if __name__ == "__main__":
main()
21. Department of Electrical Engineering
The University of Faisalabad
When “else condition” does not work?
There might be many instances when your “else condition” won’t give you the desired result. It
will print out the wrong result as there is a mistake in program logic. In most cases, this
happens when you have to justify more than two statement or condition in a program.
def main():
x, y = 8, 8
if (x < y):
st = "x is less than y"
else:
st = "x is greater than y"
print(st)
if __name__ == "__main__":
main()
22. Department of Electrical Engineering
The University of Faisalabad
Here both the variables are same (8,8) and the program output is “x is greater than y”, which
is WRONG. This is because it checks the first condition (if condition in Python), and if it fails,
then it prints out the second condition (else condition) as default. In next step, we will see how
we can correct this error.
How to use “elif” condition?
To correct the previous error made by “else condition”, we can use “elif” statement. By using
“elif” condition, you are telling the program to print out the third condition or possibility when
the other condition goes wrong or incorrect.
Example:
def main():
x, y = 8, 8
if (x < y):
st = "x is less than y"
elif (x == y):
st = "x is same as y"
else:
st = "x is greater than y"
print(st)
if __name__ == "__main__":
main()
23. Department of Electrical Engineering
The University of Faisalabad
Python List Operations(Task_3):
Python Lists allow us to hold items of heterogeneous types. There are no arrays in Python
unlike in many other popular programming languages. But the Python Lists would be sufficient
for all the requirements where you may need arrays.
In this lab, we will learn how to create a list in Python; access the list items; find the number of
items in the list, how to add an item to list; how to remove an item from the list; loop through
list items; sorting a list, reversing a list; and many more transformation and aggregation actions
on Python Lists.
Given below are some of the most widely used list operations in Python.
Python List Length:
Python List Length represents the number of elements in the list.To get the length of list in
Python, call the python global function len() with the list passed as argument.
You could also use looping statements, like for loop or while loop, to find the number of
elements in a list. But, that would become inefficient, since we have inbuilt function.
Syntax – len(list)
The syntax of len() function to find the list length is as shown below.
n = len(listname)
Example:
List_car = ['Ford', 'Volvo', 'BMW', 'Tesla']
length = len(List_car)
print('Length of the list is :', length)
Code:
Output:
To append or add an item to Python List:
To append or add an item to Python List, use append() function. List.append() function modifies
the list in place and returns None.
24. Department of Electrical Engineering
The University of Faisalabad
In this labl, we shall learn how to use append() function to append an item at the end of List,
with some example programs.
Syntax – List.append():
The syntax of using append() function with a Python List is given below.
mylist.append(new_element)
where new_item is appended to the list mylist.
Example:
List_cars = ['Ford', 'Volvo', 'BMW', 'Tesla']
#append item to list
List_cars.append('Honda')
print(List_cars)
Output:
Python – Remove an Item from List:
To remove an item from Python List, you can use remove() method on the list with the item
passed as argument.
In this lab, we shall go through examples, to understand how to use remove() function, to
delete an item from the list.
Syntax – remove():
The syntax of remove() method is:
mylist.remove(thisitem)
where thisitem has to be removed from mylist.
The remove() method removes only the first occurrence of the item in the list. The subsequent
occurrences are untouched. At the end of this article, we will also learn to remove all of those
items with a specific value.
Example:
mylist = [21, 5, 8, 52, 21, 87]
item = 5
#Remove the item
mylist.remove(item)
print(mylist)
Code:
25. Department of Electrical Engineering
The University of Faisalabad
Output:
Create a dictionary froma string:
In this lab, we will be creating a dictionary from a string in python. Dictionary is a very useful
data structure in python and quite often we need to convert a string into a dictionary. This
string is of a dictionary format or similar to it. We will be going through two methods to create
a dictionary from a string.
We will create a dictionary from a string in two different ways.
Using eval() function
One scenario is that the inputted string completely resembles a dictionary object (key value
pair with colon and each pair separated by commas and all the elements inside curly brace).
Then this string can be converted to a dictionary easily using the eval() function.
Example:
str='SEMESTER-IV:'
str1='Cource Title of 4[3+1] credit hours:'
str2="{1:'ELECTRONIC CIRCUIT AND DESIGN',2:'DATA STRUCTURE AND
ALGORITHM',3:'SIGNAL AND SYSTEM'}"
dictionary = eval(str2)
print(str)
print(str1)
print(dictionary[1])
print(dictionary[2])
print(dictionary[3])
We execute the code the in fig 1.29.
26. Department of Electrical Engineering
The University of Faisalabad
Figure1.29
Run a program and give outputinfig.1.30.
Figure1.30