Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1959 of 3366
862 Views
Lists can be nested, means the elements of a list are themselves lists. In this article we will see how to find out if a given list is present as an element in the outer bigger list.With inThis is a very simple and straight forward method. We use the in clause just to check if the inner list is present as an element in the bigger list.Example Live DemolistA = [[-9, -1, 3], [11, -8], [-4, 434, 0]] search_list = [-4, 434, 0] # Given list print("Given List :", listA) print("list to Search: ", search_list) # Using in if ... Read More
617 Views
Lists are very frequently used data container in Python. While using lists we may come across a situation where the elements of the list maybe a sequence of numbers. We can add this sequence of numbers to a list using many Python functions. In this article we will explore different ways of doing that.With range and extendThe extent function allows us to increase the number of elements in a list. Will use the range function and apply extend to the list so that all the required sequence of numbers are added at the end of the list.Example Live DemolistA = [55, ... Read More
2K+ Views
Depending on the need of the program we may an requirement of assigning the values in a list to many variables at once. So that they can be further used for calculations in the rest of the part of the program. In this article we will explore various approaches to achieve this.Using for inThe for loop can help us iterate through the elements of the given list while assigning them to the variables declared in a given sequence.We have to mention the index position of values which will get assigned to the variables.Example Live DemolistA = ['Mon', ' 2pm', 1.5, '11 ... Read More
8K+ Views
For various data analysis work in python we may be needed to combine many python lists into one list. This will help processing it as a single input list for the other parts of the program that need it. It provides performance gains by reducing number of loops required for processing the data further.Using + operatorThe + operator does a straight forward job of joining the lists together. We just apply the operator between the name of the lists and the final result is stored in the bigger list. The sequence of the elements in the lists are preserved.Example Live DemolistA ... Read More
958 Views
A python list can contain tuples as its elements. In this article we will explore how to access every nth element form the tuples that are present as the elements in the given tuple.Using indexWe can design a for loop to access the elements from the list with the in clause applied for nth index. Then we store the result into a new list.Example Live DemoAlist = [('Mon', '3 pm', 10), ('Tue', '12pm', 8), ('Wed', '9 am', 8), ('Thu', '6 am', 5)] #Given list print("Given list: ", Alist) # Use index res = [x[1] for x in Alist] ... Read More
504 Views
Lists can be nested, means the elements of a list are themselves lists. In this article we will see how to find out only the positive numbers from a list of lists. In the result a new list will contain nested lists containing positive numbers.With for inHere we simply apply the mathematical operator to check for the value of elements in a list using a for loop. If the value is positive we capture it as a list and Outer for loop stores as a final list of lists.Example Live DemolistA = [[-9, -1, 3], [11, -8, -4, 434, 0]] ... Read More
7K+ Views
In html files we can simply add style in head section − //add css code We can add inline css styles as well in html directly.Generally css is separated from the html code. Third option add css is to include a css file .How to serve static files in Node.js?Generally css files are added with below tag − Express js provides a middleware to seve static file. This middleware gives read access to given folder.app.use(express.static(path.join(__dirname, ‘public’)));path: its our core module ... Read More
2K+ Views
So far we sent html code directly from the send(0 function in response object. For sending larger code, we definitely require to have a separate file for html code.sendFile() function−Response object gives a sendFile() function to return a html file to client.How to provide path to html file in sendFile() ?We import the path core module of node.js.const path = require(‘path’);path has a join function . __dirname is a global variable which holds the actual path to project main folder.path.join(__dirname, ‘views’, ‘add-user.html’); This will refer to the actual file location of add-user html code.App.jsconst http = require('http'); const express = ... Read More
413 Views
We added express router to handle routes. One single router file handles multiple routes.Adding a path for router in App.js −const http = require('http'); const express = require('express'); const bodyParser = require('body-parser'); const route = require('./routes'); const app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use('/test', route); app.use((req, res, next)=>{ res.status(404).send(' Page not found '); }); const server = http.createServer(app); server.listen(3000);In router middleware we used path −/p>app.use('/test', route);Router will handle all paths starting with /test e.g. /test/add-usernameWe have to change action in form in routes.js file −router.get('/add-username', (req, res, next)=>{ res.send(' Send '); });Routes.js file −const express ... Read More
997 Views
Now we have a App.js and route.js for handling routes. For any other http requests for which we have not added any request handling will results into an error page. Example for url ‘test’ −App.jsconst http = require('http'); const express = require('express'); const bodyParser = require('body-parser'); const route = require('./routes'); const app = express(); app.use(bodyParser.urlencoded({extended: false})); app.use(route); const server = http.createServer(app); server.listen(3000);Showing meaningful error message on incorrect url’s−We can add a all catch middleware for incorrect url at the end of all middleware’s in App.js −const http = require('http'); const express = require('express'); const ... Read More