IntroductionIn a real world corporate business setting, most data may not be stored in text or Excel files. SQL-based relational databases such as Oracle, SQL Server, PostgreSQL, and MySQL are in wide use, and many alternative databases have become quite popular.The choice of database is usually dependent on the performance, data integrity, and scalability needs of an application.How to do it..In this example we will how to create a sqlite3 database. sqllite is installed by default with python installation and doesn't require any further installations. If you are unsure please try below. We will also import Pandas.Loading data from SQL ... Read More
Let’s say the following is our string. Some text is surrounded by special character hash(#) −var values = "My Name is #yourName# and I got #marks# in JavaScript subject";We need to replace the special character with valid values. For this, use replace() along with shift().ExampleFollowing is the code −var values = "My Name is #yourName# and I got #marks# in JavaScript subject"; const originalValue = ["David Miller", 97]; var result = values.replace(/#([^#]+)#/g, _ => originalValue.shift()); console.log(result);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo298.js.OutputThis will produce the following output ... Read More
Suppose we have two strings S and T, we have to find all the start indices of S's anagrams in T. The strings consist of lowercase letters only and the length of both strings S and T will not be larger than 20 and 100.So, if the input is like S = "cab" T = "bcabxabc", then the output will be [0, 1, 5, ], as the substrings "bca", "cab" and "abc".To solve this, we will follow these steps:Define a map m, n := size of s, set left := 0, right := 0, counter := size of pdefine an ... Read More
To implement this, extract id from attr() and use replace() to replace the id attribute.ExampleFollowing is the code − Document $('[id*="-"]').each(function () { console.log('Previous Id attribute: ' + $(this).attr('id')); $(this).attr('id', $(this).attr('id').replace('-', '----')); console.log('Now Id Attribute: ' + $(this).attr('id')); }); To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −Following is the value on console −
IntroductionOne of the most basic and common operations to perform during data analysis is to select rows containing the largest value of some columns within a group. In this post, I will show you how to find the largest of each group within a DataFrame.Problem..Let us understand the task first, assume you are given a movies dataset and requested to list the most popular film of each year based on popularity.How to do it..1.Preparing the data.Well Google is full of datasets. I often use kaggle.com to get the datasets I need for my data analysis. Feel free to login to ... Read More
For this, use document.getElementById(“”) along with addEventListener().ExampleFollowing is the code − Live Demo Document FirstName: LastName: const formDetails = document.getElementById("details"); formDetails.addEventListener("submit", async (ev) => { ev.preventDefault(); var fName = document.getElementById("firstName").value; var lName = document.getElementById("lastName").value; console.log("First Name=" + ... Read More
Suppose we have two singly linked list L1 and L2, each representing a number with least significant digits first, we have to find the summed linked list.So, if the input is like L1 = [5, 6, 4] L2 = [2, 4, 8], then the output will be [7, 0, 3, 1, ]To solve this, we will follow these steps:carry := 0res := a new node with value 0curr := reswhile L1 is not empty or L2 is not empty or carry is non-zero, dol0_val := value of L1 if L1 is not empty otherwise 0l1_val := value of L2 if ... Read More
IntroductionOne of the basic limitation of unpacking is that you must know the length of the sequences you are unpacking in advance.How to do it..random_numbers = [0, 1, 5, 9, 17, 12, 7, 10, 3, 2] random_numbers_descending = sorted(random_numbers, reverse=True) print(f"Output *** {random_numbers_descending}")Output*** [17, 12, 10, 9, 7, 5, 3, 2, 1, 0]If I now wanted to find out the largest and second largest from the numbers, we will get an exception "too many values to unpack".print(f"Output *** Getting the largest and second largest") largest, second_largest = random_numbers_descendingOutput*** Getting the largest and second largest--------------------------------------------------------------------------- ValueError Traceback (most recent call last) ... Read More
Following is how you can validate RadioBoxes with jQuery −ExampleFollowing is the code − Live Demo Document Gender: Male Female isStudent: yes No var nameValues = 'gen;student'.split(';'); $(function () { $("form").on("submit", function (ev) { if (nameValues.filter(val => $(`input[name=${val}]:checked`).length === 0).length > 0) { ... Read More
ProblemYou want to perform various calculations (e.g., minimum value, maximum value, sorting, etc.) on a dictionary of data.Solution.We will create a dictionary with tennis players and their grandslam titles.PlayerTitles = { 'Federer': 20, 'Nadal': 20, 'Djokovic': 17, 'Murray': 3, 'Theim' : 1, 'Zverev': 0 }1.We have a dictionary with player names and the grandslam titles won by each player. Now let us try to find out the player with least number of titles#type(PlayerTitles) print(f"Output *** The minimum value in the dictionary is {min(PlayerTitles)} ")Output*** The minimum value in the dictionary is Djokovic2. This is ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP