Home » Search results for 'python dictionary'

How to Remove Duplicates From a List In Python, With Examples

Python remove duplicates from list

This article explores several ways to remove duplicate items from lists in the Python programming language. Using The dict.fromkeys() Method To Remove Duplicates From a List in Python This is the fastest way to remove duplicates from a list in Python. However, the order of the items in the list is not preserved. The fromkeys() method creates a dictionary (a collection of key:value pairs) with keys from a supplied sequence of elements (in this case, a list). As a dictionary cannot contain duplicate keys, they are removed. … Read more

Home » Search results for 'python dictionary'

What is a Tuple in the Python Programming Language?

python tuple

A Tuple is a type of variable in Python – a data structure containing multiple parts. It’s a collection (or array) of data – but a specific kind of collection. It’s Ordered (Indexed) Elements in a tuple are stored in order – stored with an index or position – their position in the collection is fixed, and they can be found by their position. It’s Unchangeable (Or Immutable) Once a tuple is created, elements in it cannot be moved, removed, added, or altered. Duplicates are Allowed Duplicate values are allowed as tuples are indexed, so multiple elements with the same … Read more

Home » Search results for 'python dictionary'

Python “while” Loops [with Examples]

python while loops

This tutorial explains how to create loops in Python by using the “while” statement. Included below are the syntax and examples. In programming (and thus, in Python), a loop is a statement which will execute a block of code repeatedly until a condition is met, or the loop is broken out of manually. This article will look at Python Loops and conventions to use when writing them. Looping with the while statement, Syntax and Example Here is a basic loop which will increment (add 1) the variable ‘i’ … Read more

Home » Search results for 'python dictionary'

Boolean Operators: Comparing Values in Python

Boolean Operators in python

Python is widely used for both scripting and automation on Linux, as well as building web and standalone applications. Python is designed to be easy to learn, easy to write, and easy to read. It’s a great multi-purpose programming language. Boolean Values This article covers how boolean operators work in Python. In programming, a boolean value is either TRUE or FALSE. When comparing values in Python, a boolean value is returned allowing you to store the result of the comparison, or take a certain action … Read more

Home » Search results for 'python dictionary'

How to Get the Length of a List in Python

How to get the length of a list in Python

This tutorial will teach you how to find the length of a list (array) in Python using some code examples. There are four data structures built into Python: tuples, sets, dictionaries, and lists. They are important for programmers because they allow for iteration over their contents. When we talk about data structures such as lists in Python, we are referring to a collection data type. Lists in Python can be ordered and changed. Also, unlike the sets collection type, a list allows for duplicated entries, … Read more

Home » Search results for 'python dictionary'

How to Reverse a List in Python

How to Reverse a List in Python

Even outside of programming, people perform list reversal regularly, for example, to re-order eBay items from high to low then low to high. It is a handy operation, and Python provides several ways to accomplish it. Method 1: Using the built-in reverse() function This method has the advantage of being simple and easy to understand when using someone else’s code. For example, if we have stored our list in “staffNames”: staffNames = [“Abigail”, “Chris”, “Denise”, “Fred”] staffNames.reverse() When executed, this method doesn’t automatically give a … Read more

Home » Search results for 'python dictionary'

Concatenating (Joining) Strings in Python

string concatenation python

Let’s look at two ways you can concatenate (which is a fancy word for join or merge) two or more strings in Python. It’s also worth checking out our article on converting integers to strings in Python. A Note On Immutable Strings Strings in Python are immutable and cannot be changed once defined. This means that whenever you join two strings, a new string is created (ie. the original is not modified!). This has both performance side effects and affects how you should structure your code: … Read more

Home » Search results for 'python dictionary'

How To Remove Items From A List in Python (With Examples)

python remove items from list

Python is widely used for both scripting and automation on Linux, as well as building web and standalone applications. Python is designed to be easy to learn, easy to write, and easy to read. It’s a great multi-purpose programming language. Python has several different types of arrays for storing data. Lists are arrays which allow you to store items. Items in lists can be altered, and are stored in a specific order. Syntax and Examples There are several methods you can use to remove an … Read more

Home » Search results for 'python dictionary'

for…in Loops in JavaScript – How to Use Them

JavaScript for...in loop

The for…in loop in JavaScript loops over all of the properties in an object. This article will explain why and how to use it. JavaScript Objects JavaScript objects are a kind of variable which store the properties for an item you are representing in your code. For example, you may have a car object, which of which the make, year, model, and colour of a car are it’s properties. Each car object would have it’s own separate list of properties which define that car. JavaScript objects can also be used as hash tables – providing … Read more

Home » Search results for 'python dictionary'

PHP foreach Loop [With Examples]

PHP foreach Loop

Looping over arrays and iterating over an object’s attributes form the foundation of a lot of application logic. The foreach construct in PHP can do both and is a crucial tool for building your application logic. PHP foreach Syntax The syntax for a foreach construct in PHP is as follows: foreach (iterable_expression as $value) { # statement(s) } Or, if you also wish to access the array key as well: foreach (iterable_expression as $key => $value) { # statement(s) } Note that: iterable_expression is the variable or value to … Read more

Categories PHP