Ordered lists in HTML are the ones in which all the elements of the list are placed in a proper sequence of numbers, alphabets, or Roman numerals. These lists are very helpful whenever you wish to list down multiple elements that are supposed to occur in a certain order. In this guide, we will share with you the different examples that will depict the usage of the ordered lists in HTML.
Using the Ordered Lists in HTML
The ordered lists in HTML can be used in multiple ways. The following four examples will demonstrate some of their usage scenarios:
Example #1: Simple Usage of the Ordered Lists
In this example, we will learn to create a simple ordered list in HTML. For doing so, you will have to go through the HTML script shown in the following image:
The ordered lists in HTML can be created by using the “ol” tag. Merienda you apply this tag, you mention all the elements of this ordered list by enclosing them within the “li” tag. In this example, we create an ordered list of three courses. Therefore, we use the “ol” tag followed by the three “li” tags in this script.
Then, after saving this script and executing it within our browser, the following web page appears on our screen. You can see that our specified courses are displayed in the form of an ordered list on this web page.
Example #2: Ordered Lists with Upper Case Letters
It is not necessary to only have the ordered list of numbers. We can also have the ordered lists of alphabets. The HTML script shown in the following image will demonstrate how to create an ordered list with the upper case letters in HTML.
In this HTML script, we display the three different directions in the form of an ordered list. However, this time, we want an ordered list of the upper case letters. Therefore, we use an additional “type” attribute with the “ol” tag to mention the exact type of the ordered list. We equalize this attribute to “A” for creating an ordered list with the upper case alphabets. Then, we simply mention all the elements of this ordered list with the “li” tag.
Our ordered list with the upper case alphabets is shown in the following image:
Note: If you replace “A” in the previous script with “a”, “I”, “i”, or “1”, then our ordered list will have small case letters, upper case Roman numerals, lower case Roman numerals, or numbers, respectively. However, by default, an ordered list in HTML comprises numbers. Therefore, you do not need to specifically mention the type “1” in this case.
Example #3: Ordered Lists with a Random Starting Point
At times, you do not want your ordered list to start with “1”. Rather, you want to have a random starting point for it. To do that, you can use the HTML script shown in the following image:
In this script, we want our ordered list to start from the number “10”. Therefore, we use the “start” attribute with the “ol” tag and equalize it to “10”. Then, we mention the three different elements with the “li” tag.
Our ordered list with a starting point of our choice other than “1” is shown in the following image:
Example #4: Nested Ordered Lists
In this example, we will learn to create the nested ordered lists, i.e. ordered lists within an ordered list in HTML. The HTML script for this purpose is shown in the following image:
In this example, we want to have an outer ordered list of the different drinks. Inside each category, we wanted to have the inner ordered lists to mention the different drinks belonging to each of these categories. Therefore, we nested the “ol” and “li” tags accordingly in the HTML script shown in the previous image.
The following web page shows our nested ordered list in HTML:
Conclusion
This tutorial is to discuss the usage of the ordered lists in HTML. We gave you a brief introduction of the ordered lists in HTML followed by a few examples that were meant to bring more clarity to this concept. After understanding these examples well, you will be able to use the ordered lists in HTML quiebro effectively.
https://codecubit.com/wp-content/uploads/2022/07/Ordered-Lists-in-HTML-1.png354422RoboLinuxhttps://codecubit.com/wp-content/uploads/2022/05/logo340x156.svgRoboLinux2022-07-23 00:13:082022-07-23 00:14:35Ordered Lists in HTML
In C# programming, lists are used for storing and processing different data. We can perform different tasks on these lists. One of them is combining two different lists. In C# programming, combining two lists means joining or merging two different lists into one new list. We have different methods to combine lists in C#. We will use three different methods to combine two lists in C# programming. Here, we are going to perform different examples in Ubuntu 20.04.
We will demonstrate an example in which we use the AddRange() method for combining two different lists in C# programming. We perform the given examples in Ubuntu 20.04 text editor. When using the Ubuntu 20.04 text editor, we must save our file with the “.cs” extension. Then, explain the following code in detail:
We start our program with the “using System” library. We use this library to access classes and functions. It provides us with many valuable functions and classes. The “System.Collections.Generic ” is here for good performance containing different interfaces and classes which define generic collections. After invoking the “main” function, we create a new list named “Vegetables”, which is a string data type. We use the “new” keyword for creating a new list. When this new list is created, we have to pass some string data to this list. We add “Potato”, “Chilli”, “Garlic”, and “Tomato” to this list.
Now, we have to create another list so that we can combine both lists. So, we will form another list with the name “Fruits”. We created this list with the same method as we created the first one. When the second list is created, we add some fruits’ names to this list. Here, you can see that we add “Apple”, “Mango”, “Banano” and “Orange” to the second list. Now, it’s time to add both lists using the “AddRange” method. We use the same syntax of the AddRange() method previously discussed. Here, we give the name of the first list, which is “Vegetables”. Then, use the AddRange method and the name of the second list, “Fruits”.
In this code, the line “Vegetables.AddRange(Fruits)” is used for combining these two lists. After this, we will print this combined list with the help of “Console.WriteLine” statements. First, this statement prints the line. Then, we use String. Join (“,”, Vegetables) inside the Console.WriteLine statement to print the combined list. In this, “Join()” is a method to combine list elements using “,” to separate each element of the list.
As we use the Ubuntu 20.04 to perform these examples, we have to run some commands for the output on the terminal of Ubuntu 20.04. First, you must launch the Ubuntu terminal and write the “mcs” command. It is used for the compiling of our source code. When using this “mcs” command, we put the “.cs” extension with the file_name. You have to press Enter to run this “mcs” command. When this command runs successfully and there is no error in our code, it creates an executable file for us.
After that, we use another command which is the “mandril” command here. This command is used for the execution of our code. When we use this command, we use the “.exe” file extension. Press Enter to run this “mandril” command. The output of the code is rendered on the following screen:
In this output, you can see that it prints the two lists in a signal list, which means it combines both lists in one list and displays both lists in a single line or a single list.
Example # 2: By Using ForEach Loop Method
Now, we explore another example in which we use the ForEach Loop method to combine two lists. We perform different examples by using different methods for combining two lists.
The “Using System” is here, which contains classes and functions. Then, we have “System.Collections.Generic”, which contains interfaces and classes. The class is public with the name “Program”. We must have the “Main” function in our program. Then, we have to create two different and separate lists. We create the first list with the name “Stationery” by using the “new” keyword. We must add some elements to this list. So, we add “Pencil”, “Marker”, “Eraser”, and “Color” to this “Stationery” list.
After creating the first list, we create another list of “Subjects” and add different subject names to this second list. Here, we add “English”, “Computer”, “Biology”, and “Mathematics” to this “Subject” list. Now, we have to merge these two lists using the “ForEach” Loop method. When we use this ForEach loop method, we must follow the syntax of this method. First, we have to give the name of the second list and use the ForEach loop. Inside this ForEach loop, we give the name of any list with a fat arrow “=>”.
After this fat arrow gives the name of the first list and then puts “Add” and inside add again gives the name of any list. In this code “Subject.ForEach(Things => Stationery. Add (Things)” line is used to merge two lists using the ForEach loop method. Now, we print this merged list by using “Console.WriteLine”. We print this list with the same method we deliberated in our preceding example. The output of our code is provided in the image provided below:
Example # 3: By Using Enumerable.Concat() Method
We are performing this given example for you to easily learn how to use different methods to combine two lists.
Here, we create a list of the variable named “listA” by using the “new” keyword and a list of string data types. We add different elements using the “list_name.Add()” method. The name of the first list is “listA” here. We add “Computer”, “Keyboard”, and “Mouse” to this list by using the “Add ()” method. We will print the list first in this code and combine both lists after printing both lists separately. We print the first list using the foreach loop. We initialize a variable with the name “e”, which stores all the elements of the “listA” and prints all elements using the “Console.WriteLine” method.
After printing this first list, we create and print a new list name, “listB” with the same method that we used to create and print the first list, “listA”. When both lists are created, we combine these lists. And for combining, we use the third method, which is “Enumerable.Concat()”. We create another list named “FinalList” and initialize this with the “Enumerable.Concat()” method.
First, we give the name of the first list, “listA” then “Concat” inside this, we give the name of the second list, which is “listB” and the ToList(). The ToList() gets the elements from the list and returns the new list. After all this, we print the concatenate or combined list using the same method we used in our previous examples. The output of this code is in the following image:
Conclusion:
This tutorial discussed how to combine two lists in C# programming in Ubuntu 20.04 by using different methods. This tutorial explained three different methods for combining two lists. We have also provided screenshots of the codes along with the output of each code for your better understanding. In addition, we utilized three different examples in which we use three different methods for merging or combining two lists in C# programming. I hope you will easily learn this concept, and this tutorial will be helpful for you in the future.
https://codecubit.com/wp-content/uploads/2022/06/word-image-183393-1.png360621RoboLinuxhttps://codecubit.com/wp-content/uploads/2022/05/logo340x156.svgRoboLinux2022-06-11 04:20:492022-06-11 04:28:38How To Combine Two Lists in C#
Lists are similar to dynamically allocated arrays, declared in other languages. Lists do not always have to be homogeneous, making Python’s most powerful feature. Integers, Strings, and Objects can all be found in a single list. Lists are changeable, which means they can be changed after they are created.
In Python, lists are ordered and counted. Every member inside the list has its separate position in the list, allowing duplication of the list’s elements while maintaining the credibility of each member. Lists help store and iterate through an iteration of data.
How to Create it?
This artifact will teach you to create and initialize a Python list of lists. A list of lists is a nested list with one or more lists. There are numerous methods for creating a list of lists. A different method will be used to construct a list of lists. Then, we will explore how to access list items after we’ve created a list of lists. Let’s look at a few examples.
Example 1: Using the append() Function to Create a List of Lists in Python in Ubuntu 20.04
The List append() function in Python is used to append and add items to the end of a List. In this illustration, we are just adding a list to a list as an item using the append() method.
Let’s see the implemented python code in the following image. In our first step, we created two list arrays represented with “list_x” and “list_y.” The lists here are initialized with different integer values.
After that, we have created a new list as “list_z,” which is initially empty. We are going to add the above lists to that list. Then, we have called the append function for the “list_z,” to which we want to append the above-initialized lists. The append function takes the list_x and the list_y as an argument individually. This append method will add the whole list in the list_z along with the elements of the list. The print function is called for printing the lists of newly generated “list_z.”
list_x =[2,4,6,8]
list_y =[3,5,7,9]
list_z =[]
list_z.append(list_x)
list_z.append(list_y)
print(list_z)
The lists are appended to the one list as shown on the output terminal screen.
Example 2: Using the List Initializer to Create a List of Lists in Python in Ubuntu 20.04
An alternative way to make a list in Python, use the list initializer syntax. We can use this approach to make a list of lists by providing lists to the list initializer as elements.
At the beginning of the python code below, we have defined two lists separately. The lists are represented as “list1” and “list2”. These lists are stored with some integral values, as shown. Then, we have the list initializer method for which we have declared a new list as “list3”. We have initialized the “list3” with the “list1” and “list2”.
Here, We treat lists as items by using a list initializer. By using lists as items, we can make a list of lists. It’s the most straightforward method for making a list of lists. The list3 will be printed, which has both the above-specified lists.
list1 =[21,22,23,24]
list2 =[25,25,27,28]
list3=[list1, list2]
print(list3)
The output here shows the list of lists in the prompt shell as follows.
Example 3: Using the for-loop
We will create a more comprehensive list of lists by explicitly utilizing the append() technique with the for loop.
In the following Python script, we have established an empty list. The list is given the name “mylist.” Then, we have a for loop for creating the list of lists. We have defined the range of the lists in the list by using the range method and passed the value “3” as an argument. The for loop has the variable “m,” which will iterate over the range defined for the list.
After that, we have called the append method, which will append the three lists in the list. Now, the for loop is invoked again for adding the elements in the lists in the range of “6”. The print function will print the three lists in the list and the elements in the lists.
mylist =[]
for m inrange(3):
mylist.append([])
for n inrange(6):
mylist[m] .append(n)
print(mylist)
The output is as follows:
Example 4: Using the List Comprehension to Create a List of Lists in Python in Ubuntu 20.04
In Python, list comprehension is a simple but elegant approach to generating lists. We generate lists using for loops and logic enclosed in square brackets using this strategy.
First of all, we have defined a list that now has string elements. Then, we created another list with the name “colors.” The list “colors” is an empty list for the time being. After that, we called the list “colors” and applied the for loop cycle to it. The for loop iterates over each item in the list and adds the elements in the list by creating a new variable, “elements.” The list “colors” of the lists will be printed at the end.
list=[‘pink’,‘red’,‘white’,‘blue’,‘green’]
colors =[]
colors =[[elements]for elements inlist]
print(colors)
We can also create a list of lists in python through this approach. This one is the shortest method among all.
Example 5: Accessing the Elements From the List of Lists in Python
By utilizing an index, we may access elements. The list index begins with 0 and ends with n-1, whereby n is the list length.
The following python program has a list initialized with some string values. The new empty list is also created as Animals. Then the for loop is applied to the list “Animal.” We are adding the list in the list “Animals” by using a for loop. In the end, we are displaying the list and accessing the list’s elements.
list=[‘cat’,‘dog’,‘hen’,‘parrot’,‘panda’]
Animals =[]
Animals =[[items]for items inlist]
print(Animals)
print(Animals[1])
print(Animals[3])
print(Animals[4])
The list of lists is created and also accessed the list elements by the index location. The output is as follows.
Conclusion
Summing up! About creating a Python list of lists. A list of lists is a list where every value is a separate list. We have deeply gone through creating the list of lists in python. We have four different approaches that will create a list of lists in python easily and efficiently. Then, we have also accessed the list of list elements in python by the index position of the elements in the list. We hope you found it informative.
https://codecubit.com/wp-content/uploads/2022/06/word-image-8.jpeg173590RoboLinuxhttps://codecubit.com/wp-content/uploads/2022/05/logo340x156.svgRoboLinux2022-06-06 17:48:162022-06-06 17:53:51Create a List of Lists in Python