code-rag-bench/online-tutorials huggingface dataset:
PYGLET – Sprite Position

19 Sep, 2021
In this article we will see how we can access position of the sprite in PYGLET module in python. Pyglet is easy to use but powerful library for developing visually rich GUI applications like games, multimedia etc. A window is a “heavyweight” object occupying operating system resources. Windows may appear as floating regions or can be set to fill an entire screen (fullscreen). A sprite is an instance of an image displayed on-screen. Multiple sprites can display the same image at different positions on the screen. Sprites can also be scaled larger or smaller, rotated at any angle and drawn at a fractional opacity. Image is loaded with the help of image module of pyglet. Potion property tells the sprite position inside the window in form of pixels distance from x and y axis.We can create a window and sprite object with the help of commands given below 
# creating a window
window = pyglet.window.Window(width, height, title)

# creating a sprite object
sprite = pyglet.sprite.Sprite(img, x, y)
In order to create window we use position attribute with sprite objectSyntax : sprite.positionArgument : It takes no argumentReturn : It returns tuple  
Below is the implementation 
Python3
# importing pyglet moduleimport pygletimport pyglet.window.key as key   # width of windowwidth = 500   # height of windowheight = 500   # caption i.e title of the windowtitle = "Geeksforgeeks"   # creating a windowwindow = pyglet.window.Window(width, height, title)   # text text = "Welcome to GeeksforGeeks"  # creating label with following properties# font = cooper# position = 250, 150# anchor position = centerlabel = pyglet.text.Label(text,                          font_name ='Cooper',                          font_size = 16,                          x = 250,                           y = 150,                          anchor_x ='center',                           anchor_y ='center')  # creating a batchbatch = pyglet.graphics.Batch() # loading geeksforgeeks imageimage = pyglet.image.load('gfg.png')   # creating sprite object# it is instance of an image displayed on-screensprite = pyglet.sprite.Sprite(image, x = 200, y = 230)   # on draw event@window.eventdef on_draw():           # clear the window    window.clear()           # draw the label    label.draw()         # draw the image on screen    sprite.draw()       # key press event    @window.eventdef on_key_press(symbol, modifier):       # key "C" get press    if symbol == key.C:                 # printing the message        print("Key : C is pressed")         # image for iconimg = image = pyglet.resource.image("gfg.png") # setting image as iconwindow.set_icon(img) # accessing position of the spritevalue = sprite.position # creating text from spritetext = "Position : " + str(value) # setting text to the labellabel.text = text    # start running the applicationpyglet.app.run()
Output : 
singghakshay
anikakapoor
Python-gui
Python-Pyglet
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
SAS | Date Formats and Informats

30 Jul, 2019
Informats is used to tell SAS how to read a variable whereas Formats is used to tell SAS how to display or write values of a variable.
Informats is basically used when you read in sample data which is being created using CARDS/DATALINES statement or read or import data from either an external file (Text/Excel/CSV).
Formats can be used in both Data Steps and PROC Steps whereas Informat can be used only in Data Steps.
Example: Read Dates in SAS
In the example below, we have used INFORMATS ddmmyy8. and ddymmyy10. to read dates in SAS. It creates a dataset called sampledata which is stored in WORK library.DATA sampledata;    INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;    CARDS;20-07-19 20-07-2019 ;RUN;The INFORMATS ddmmyy8. is used to read 20-07-19 date and ddmmyy10. to read 20-07-2019 date. In defined syntax above, 8 and 10 refers to width of the date.The created dataset looks like below –It returns 21750 as it is in the SAS date value form. It is not meaningful if you look at the value. You cannot tell which date it is.
DATA sampledata;    INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;    CARDS;20-07-19 20-07-2019 ;RUN;
The INFORMATS ddmmyy8. is used to read 20-07-19 date and ddmmyy10. to read 20-07-2019 date. In defined syntax above, 8 and 10 refers to width of the date.
The created dataset looks like below –
It returns 21750 as it is in the SAS date value form. It is not meaningful if you look at the value. You cannot tell which date it is.
To display the date in usual date format, use FORMAT statement.DATA sampledata;    INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;    FORMAT date1 ddmmyy8. date2 ddmmyy10.;    CARDS;20-07-19 20-07-2019 ;RUN;Output:
DATA sampledata;    INPUT @6 date1 ddmmyy8. @15 date2 ddmmyy10.;    FORMAT date1 ddmmyy8. date2 ddmmyy10.;    CARDS;20-07-19 20-07-2019 ;RUN;
Output:
How to read DD-MMM-YY formatYou can use date11. format for both DD-MMM-YY and DD-MMM-YYYY format.DATA temp;    INPUT @6 dt date11.;    FORMAT dt date11.;    CARDS;20-jul-19 ;    PROC PRINT noobs;RUN;Output:
You can use date11. format for both DD-MMM-YY and DD-MMM-YYYY format.
DATA temp;    INPUT @6 dt date11.;    FORMAT dt date11.;    CARDS;20-jul-19 ;    PROC PRINT noobs;RUN;
Output:
SAS Programming
Programming Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Decorators with parameters in Python
C# | Data Types
Difference between Shallow and Deep copy of a class
Shallow Copy and Deep Copy in C++
Top 10 Programming Languages to Learn in 2022
Kotlin Array
Advantages and Disadvantages of OOP
Top 10 Fastest Programming Languages
Difference between while and do-while loop in C, C++, Java
Difference between for and while loop in C, C++, Java
Python – Remove Dictionary Key Words

10 May, 2020
Sometimes, while working with Python strings, we can have a problem in which we need to remove all the words from a string which are a part of key of dictionary. This problem can have application in domains such as web development and day-day programming. Let’s discuss certain ways in which this task can be performed.
Method #1 : Using split() + loop + replace()The combination of above functions can be used to solve this problem. In this, we perform the task of converting string to list of words using split(). Then we perform a replace of word present in string with empty string using replace().
# Python3 code to demonstrate working of # Remove Dictionary Key Words# Using split() + loop + replace()  # initializing stringtest_str = 'gfg is best for geeks'  # printing original stringprint("The original string is : " + str(test_str))  # initializing Dictionarytest_dict = {'geeks' : 1, 'best': 6}  # Remove Dictionary Key Words# Using split() + loop + replace()for key in test_dict:    if key in test_str.split(' '):        test_str = test_str.replace(key, "")  # printing result print("The string after replace : " + str(test_str)) 
The original string is : gfg is best for geeks
The string after replace : gfg is  for 

 
Method #2 : Using join() + split()This is yet another way in which this task can be performed. In this, we reconstruct new string using join(), performing join by the empty string after split.
# Python3 code to demonstrate working of # Remove Dictionary Key Words# Using join() + split()  # initializing stringtest_str = 'gfg is best for geeks'  # printing original stringprint("The original string is : " + str(test_str))  # initializing Dictionarytest_dict = {'geeks' : 1, 'best': 6}  # Remove Dictionary Key Words# Using join() + split()temp = test_str.split(' ')temp1 = [word for word in temp if word.lower() not in test_dict]res = ' '.join(temp1)  # printing result print("The string after replace : " + str(res)) 
The original string is : gfg is best for geeks
The string after replace : gfg is  for 

Python dictionary-programs
Python string-programs
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Python OOPs Concepts
Iterate over a list in Python
Introduction To PYTHON
Global keyword in Python program

Sometimes we declare a variable but we may need to modify or access the values outside the current scope of its declaration which may be anywhere in the current program. In such scenario, we use the Global keyword with the variable name inside the function where the variable is declared. If the variable is not inside a function, then it is automatically global in scope.
In the below example we see a value outside a function, but we are able to access it from inside a function. Because such a variable is already global in scope.
x = 56
def func():
y = x *2
   return y
print(func())
Running the above code gives us the following result:
112
In the next example we attempt to change the value of a variable inside a function and get an error.
x = 56
def func():
   y = x *2
   x = x+2
      return y
print(func())
Running the above code gives us the following result:
nboundLocalError: local variable 'x' referenced before assignment
The only way we can modify the value of a variable with global scope inside a function is by declaring it as a global variable inside a function.
x = 56
def func():
global x
   x = x + 2
   y = x *2
      return y
print(func())
Running the above code gives us the following result
116
In case of nested function, we create the global variable in the innermost function as shown in the below example.
 Live Demo
def func_out():
   x = 56
   def func_in():
      global x
      x = 20
      print("x is: ",x)
      x = x + 3
      y = x *2
      print ("y is: ",y)
   func_in()
func_out()
print("x is: ",x)
Running the above code gives us the following result:
x is: 20
y is: 46
x is: 23
How do I execute a string containing Python code in Python?

If you want to execute Python statements, you can use exec(string). For example,
>>> my_code = 'print "Hello World!"'
>>> exec(my_code)
Hello World!
But if you just want to evaluate the value of an expression, you can use eval(). For example,
>>> my_expression = "5 + 3"
>>> eval(my_expression)
8
 Note: Be very cautious while using both eval and exec as they are very powerful functions
and can cause very subtle bugs/ security loopholes in your code.
JSF - f:validateRegex

f:validateRegex tag is used to validate a string value to a required format.
<f:validateRegex pattern = "((?=.*[a-z]).{6,})" />

pattern
Formatting pattern
Let us create a test JSF application to test the above tag.
package com.tutorialspoint.test;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name = "userData", eager = true)
@SessionScoped
public class UserData implements Serializable {
   private static final long serialVersionUID = 1L;
   private String password;
   
   public String getPassword() {
      return password;
   }
   
   public void setPassword(String password) {
      this.password = password;
   }   
}
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml"   
   xmlns:h = "http://java.sun.com/jsf/html"
   xmlns:f = "http://java.sun.com/jsf/core">
   
   <h:head>
      <title>JSF tutorial</title>			
   </h:head>
   
   <h:body>    
      <h2>h:validateRegex Example</h2>
      <!-- password contains lower case letters only and.
      length of the password should be greater than 6. -->
      
      <h:form>
         <h:inputSecret id = "passwordInput" value = "#{userData.password}" 
            label = "password" >
            <f:validateRegex pattern = "((? = .*[a-z]).{6,})" />
         </h:inputSecret>			
         <h:commandButton value = "submit" action = "result"/>
         <h:message for = "passwordInput" style = "color:red" />
      </h:form>
   
   </h:body>
</html>
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns = "http://www.w3.org/1999/xhtml"
   xmlns:f = "http://java.sun.com/jsf/core"    
   xmlns:h = "http://java.sun.com/jsf/html">
   
   <h:head>
      <title>JSF Tutorial!</title>   
   </h:head>
   
   <h:body>
      <h2>Result</h2>
      <hr />     
      Password: #{userData.password}     
   </h:body>
</html>  
Once you are ready with all the changes done, let us compile and run the application as we did in JSF - First Application chapter. If everything is fine with your application, this will produce the following result.
Enter an invalid value. Following will be the output.
Enter a valid value. Following will be the output.

    37 Lectures 
     3.5 hours 

 Chaand Sheikh
 Print
 Add Notes
 Bookmark this page
IFNULL in MySQL - GeeksforGeeks

03 Mar, 2018
Given a TABLE, in this TABLE, it prints entry of the table. If table is empty then it gives NULL.
Examples:
QUESTION : Given an employee table, print name from the given table which id equals to 2.Output : Geek2
QUESTION : Given same Employee table, print name from the given table which id equals to 5.Output : NULL
Approach: In this case, we use here IFNULL. IFNULL print the null if the table is an empty or other condition.
Query:-
SELECT 
IFNULL(
  (SELECT NAME 
  from employee
  where id = 2),
  'NULL') as NAME;

Output:-
Geek2

Query:-
SELECT 
IFNULL(
  (SELECT NAME 
  from employee
  where id = 5),
  'NULL') as NAME;

Output:-
NULL

mysql
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
SQL Trigger | Student Database
SQL | Views
CTE in SQL
Difference between DELETE, DROP and TRUNCATE
How to Update Multiple Columns in Single Update Statement in SQL?
Difference between SQL and NoSQL
Difference between DDL and DML in DBMS
SQL Interview Questions
What is Temporary Table in SQL?
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter
C library function - atan()

The C library function double atan(double x) returns the arc tangent of x in radians.
Following is the declaration for atan() function.
double atan(double x)
x − This is the floating point value.
x − This is the floating point value.
This function returns the principal arc tangent of x, in the interval [-pi/2,+pi/2] radians.
The following example shows the usage of atan() function.
#include <stdio.h>
#include <math.h>

#define PI 3.14159265

int main () {
   double x, ret, val;
   x = 1.0;
   val = 180.0 / PI;

   ret = atan (x) * val;
   printf("The arc tangent of %lf is %lf degrees", x, ret);
   
   return(0);
}
Let us compile and run the above program that will produce the following result −
The arc tangent of 1.000000 is 45.000000 degrees


    12 Lectures 
     2 hours 

 Nishant Malik

    12 Lectures 
     2.5 hours 

 Nishant Malik

    48 Lectures 
     6.5 hours 

 Asif Hussain

    12 Lectures 
     2 hours 

 Richa Maheshwari

    20 Lectures 
     3.5 hours 

 Vandana Annavaram

    44 Lectures 
     1 hours 

 Amit Diwan
 Print
 Add Notes
 Bookmark this page
How to bind multiple events with one "bind" in Tkinter?

For a particular application, if we want to perform multiple tasks with the help of buttons defined in it, then we can use the bind(Button, callback) method which binds the button and the event together to schedule the running of the event in the application.
Let us suppose we want to bind multiple events or callback with a single <bind>, then we have to first iterate over all the widgets to get it as one entity. The entity can be now configurable to bind the multiple widgets in the application.
# Import the required libraries
from tkinter import *
from tkinter import ttk

# Create an instance of tkinter frame or window
win = Tk()

# Set the size of the window
win.geometry("700x350")

def change_bgcolor(e):
   label.config(background="#adad12")

def change_fgcolor(e):
   label.config(foreground="white")

# Add a Label widget
label = Label(win, text="Hello World! Welcome to Tutorialspoint", font=('Georgia 19 italic'))
label.pack(pady=30)

# Add Buttons to trigger the event
b1 = ttk.Button(win, text="Button-1")
b1.pack()

# Bind the events
for b in [b1]:
   b.bind("<Enter>", change_bgcolor)
   b.bind("<Leave>", change_fgcolor)

win.mainloop()
If we run the above code, it will display a window that contains a button.
When we hover over the button, it will change the background color of the Label. Leaving the button will change the font color of the Label widget.
How to Setup Sublime Text 3 for Java in Windows? - GeeksforGeeks

02 Jul, 2020
Java is one of the most popular and widely-used object-oriented programming languages. Java syntax is similar to C/C++. But Java does not provide low-level programming functionalities like pointers. Also, Java codes are always written in the form of classes and objects. The Java codes are first compiled into byte code (machine-independent code). Then the byte code is run on Java Virtual Machine (JVM) regardless of the underlying architecture.
Written by a Google engineer sublime text is a cross-platform IDE developed in C++ and Python. It has basic built-in support for Python. Sublime text is fast and you can customize this editor as per your need to create a full-fledged Python development environment. You can install packages such as debugging, auto-completion, code linting, etc. There are also various packages for scientific development, Django, Flask, and so on.
Java can be downloaded from oracle.com. To install Java compiler on Windows, go through How to install Java on Windows?
Sublime Text 3 can be downloaded from its official site sublimetext.com. To install sublime text 3 on Windows, go through How to install Sublime Text 3 in Windows?
Step 1: Click the Advanced system settings link.
Step 2: Click Environment Variables. In the section System Variables, find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
Step 3: In the Edit System Variable (or New System Variable) window, specify the value of the PATH environment variable. Click OK. Close all remaining windows by clicking OK.
After the installation process is over and we are done with the environment setup, we need to test whether our compiler and IDE working or not. For this we will write a simple output based program:
public class HelloWorld {    public static void main(String[] args)    {        System.out.println("GeeksforGeeks");    }}
How To
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Align Text in HTML?
How to filter object array based on attributes?
How to Install FFmpeg on Windows?
How to integrate Git Bash with Visual Studio Code?
How to Install and Run Apache Kafka on Windows?
Arrays in Java
Split() String method in Java with examples
For-each loop in Java
Arrays.sort() in Java with examples
Reverse a string in Java
Simplified Fractions in C++

Suppose we have an integer n, we have to find a list of all simplified fractions between 0 and 1 (exclusive) such that the denominator <= n. Here the fractions can be in any order.
So, if the input is like n = 4, then the output will be ["1/2","1/3","1/4","2/3","3/4"] as "2/4" is not a simplified fraction because it can be simplified to "1/2".
To solve this, we will follow these steps −
Define an array ret
Define an array ret
for initialize i := 2, when i <= n, update (increase i by 1), do −for initialize j := 1, when j < i, update (increase j by 1), do −c := gcd of i and ja := j / cb := i / cinsert (a as string concatenate "/" concatenate b as string) at the end of ret
for initialize i := 2, when i <= n, update (increase i by 1), do −
for initialize j := 1, when j < i, update (increase j by 1), do −c := gcd of i and ja := j / cb := i / cinsert (a as string concatenate "/" concatenate b as string) at the end of ret
for initialize j := 1, when j < i, update (increase j by 1), do −
c := gcd of i and j
c := gcd of i and j
a := j / c
a := j / c
b := i / c
b := i / c
insert (a as string concatenate "/" concatenate b as string) at the end of ret
insert (a as string concatenate "/" concatenate b as string) at the end of ret
return an array of all unique elements present in ret
return an array of all unique elements present in ret
Let us see the following implementation to get a better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
void print_vector(vector<string> v){
   cout << "[";
   for(int i = 0; i<v.size(); i++){
      cout << v[i] << ", ";
   }
   cout << "]"<<endl;
}
class Solution {
public:
   vector<string> simplifiedFractions(int n) {
      vector<string> ret;
      for (int i = 2; i <= n; i++) {
         for (int j = 1; j < i; j++) {
            int c = __gcd(i, j);
            int a = j / c;
            int b = i / c;
            ret.push_back(to_string(a) + "/" + to_string(b));
         }
      }
      set<string> s(ret.begin(), ret.end());
      return vector<string>(s.begin(), s.end());
   }
};
main(){
   Solution ob;
   print_vector(ob.simplifiedFractions(4));
}
4
[1/2, 1/3, 1/4, 2/3, 3/4, ]
Java Examples - Comparing performance

How to compare performance of string creation ?
Following example compares the performance of two strings created in two different ways.
public class StringComparePerformance {
   public static void main(String[] args) {      
      long startTime = System.currentTimeMillis();
      
      for(int i = 0; i < 50000; i++) {
         String s1 = "hello";
         String s2 = "hello"; 
      }
      long endTime = System.currentTimeMillis();
      System.out.println("Time taken for creation" 
         + " of String literals : "+ (endTime - startTime) 
         + " milli seconds" );       
      long startTime1 = System.currentTimeMillis();
      
      for(int i = 0; i < 50000; i++) {
         String s3 = new String("hello");
         String s4 = new String("hello");
      }
      long endTime1 = System.currentTimeMillis();
      System.out.println("Time taken for creation" 
         + " of String objects : " + (endTime1 - startTime1)
         + " milli seconds");
   }
}
The above code sample will produce the following result.The result may vary.
Time taken for creation of String literals : 0 milli seconds
Time taken for creation of String objects : 16 milli seconds

 Print
 Add Notes
 Bookmark this page
How to create a database on command line in MySQL?

First, you need to open the command prompt. You can open using shortcut windows+R key.
The screenshot is as follows −
Now type CMD and press OK button −
Now the following command prompt would be visible −
Now reach the MySQL bin directory. The screenshot is as follows −
Following is the query to run MySQL in the command line to create a database −
Now you can check the database is created or not using SHOW DATABASES command −
mysql> SHOW DATABASES;
This will produce the following output −
+---------------------------+
| Database                  |
+---------------------------+
| bothinnodbandmyisam       |
| business                  |
| commandline               |
| customer_tracker_database |
| customertracker           |
| database1                 |
| databasesample            |
| demo                      |
| education                 |
| hb_student_tracker        |
| hello                     |
| information_schema        |
| javadatabase2             |
| javasampledatabase        |
| login                     |
| mybusiness                |
| mydatabase                |
| mysql                     |
| onetomanyrelationship     |
| onlinebookstore           |
| performance_schema        |
| rdb                       |
| sample                    |
| sampledatabase            |
| schemasample              |
| sys                       |
| test                      |
| test3                     |
| tracker                   |
| universitydatabase        |
| web                       |
| webtracker                |
+---------------------------+
32 rows in set (0.00 sec)
How to shuffle a std::vector in C++

A vector shuffle can be done in the Fisher-Yates shuffle algorithm.
In this algorithm, a linear scan of a vector is done and then swap each element with a random element among all the remaining element, including the element itself.
Begin
  Declare a function show().
      Pass a constructor of a vector as a parameter within show() function.
      for (auto const& i: input)
         Print the value of variable i.
      Declare v of vector type.
         Initialize some values into v vector in array pattern.
      Declare a variable size of the integer datatype.
      Call size() function to get the size of the vector.
         Initialize size = v.size().
      for (int i = 0; i < size - 1; i++)
         int j = i + rand() % (size - i).
         call swap() function to swap the values of v[i] and v[j].
      print “Elements after getting shuffled”.
      Call show() function to display the suffled value of v vector.
End.
 Live Demo
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void show(vector<int> const &input) {
   for (auto const& i: input) {
      std::cout << i << " ";
   }
}
int main() {
   vector<int> v = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
   int size = v.size();
   for (int i = 0; i < size - 1; i++) {
      int j = i + rand() % (size - i);
      swap(v[i], v[j]);
   }
   cout<<"Elements after getting shuffled"<<endl;
   show(v);
   return 0;
}
Elements after getting shuffled
2 8 5 3 1 9 4 7 6
Tryit Editor v3.7

Tryit: Center align the content in td
frozenset() in Python

This function helps in converting a mutable list to an immutable one. This is needed when we have declared a list whose items are changeable but after certain steps we want to stop allowing the elements in it to change. In such scenario, we apply the frozenset() function as shown below.
Syntax: frozenset(iterable_object_name)
In the below example we take a list, change its element and print it. Then in the next step we apply the frozenset function, and try changing the element again. In the second step we get the error showing that the list can not be modified anymore.
# Before applying forzenset()
some_days = ["Mom","Tue","Wed","Thu"]
# change element
some_days[2]="Fri"
print("some_days =",some_days)
# Apply frozenset()
fixed_days=frozenset(some_days)
print("fixed_days= ",fixed_days)
# Change element in frozenset
fixed_days[2]="Wed"
Running the above code gives us the following result −
some_days = ['Mom', 'Tue', 'Fri', 'Thu']
Traceback (most recent call last):
fixed_days= frozenset({'Thu', 'Mom', 'Fri', 'Tue'})
File "/py3.py", line 14, in
fixed_days[2]="Wed"
TypeError: 'frozenset' object does not support item assignment
LinkedList AddBefore method in C#

Add a node before a given node in C# using the AddBefore() method.
Our LinkedList with string nodes.
string [] students = {"Henry","David","Tom"};
LinkedList<string> list = new LinkedList<string>(students);
Now, let’s add node at the end.
// adding a node at the end
var newNode = list.AddLast("Brad");
Use AddBefore() method to add a node before the node added above.
list.AddBefore(newNode, "Emma");
 Live Demo
using System;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string [] students = {"Henry","David","Tom"};
      LinkedList<string> list = new LinkedList<string>(students);
      foreach (var stu in list) {
         Console.WriteLine(stu);
      }
      // adding a node at the end
      var newNode = list.AddLast("Brad");
      // adding a new node before the node added above
      list.AddBefore(newNode, "Emma");
      Console.WriteLine("LinkedList after adding new nodes...");
      foreach (var stu in list) {
         Console.WriteLine(stu);
      }
   }
}
Henry
David
Tom
LinkedList after adding new nodes...
Henry
David
Tom
Emma
Brad
Bitwise NOT operator in Golang

05 May, 2020
Bitwise NOT operator in the programming world usually takes one number and returns the inverted bits of that number as shown below:
Bitwise NOT of 1 = 0
Bitwise NOT of 0 = 1

Example:
Input : X = 010101
Output : Bitwise NOT of X = 101010

But Golang doesn’t have any specified unary Bitwise NOT(~) or you can say Bitwise Complement operator like other programming languages(C/C++, Java, Python, etc). Here, you have to use Bitwise XOR(^) operator as Bitwise NOT operator. But how?
Let’s understand how Bitwise XOR takes in any two equal length bit patterns and performs Exclusive OR operation on each pair of corresponding bits.
1 XOR 1 = 0 
1 XOR 0 = 1 
0 XOR 0 = 0
0 XOR 1 = 1 

Here, you can see the result of XOR(M, N) = 1 only if M != N else it will be 0. So here, we will use the XOR operator as a unary operator to implement the one’s complement to a number.In Golang, suppose you have a given bit M, so ^M = 1 ^ M which will be equal to one’s complement or you can say the Bitwise NOT operator result.
Example: Suppose you have the given bits as 010101.
Input: 11111111 XOR 00001111
Output: 11110000

   package main  import "fmt"  func main() {      // taking the number in the hexadecimal    // form it is 15 i.e. 00001111 in 8-bit form    var bitwisenot byte = 0x0F          // printing the number in 8-Bit    fmt.Printf("%08b\n", bitwisenot)           // using the ^M = 1 ^ M    fmt.Printf("%08b\n", ^bitwisenot)}
Output:
00001111
11110000

Here, you can see, if we simply solve the Bitwise Not of 00001111 then it will be equal to 11110000.
Go-Operators
Picked
Go Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
SVG scale Attribute

31 Mar, 2022
The scale attribute decides the displacement scale factor that must be used on a <feDisplacementMap> filter primitive. Only <feDisplacementMap> element is using this attribute.
Syntax:
scale = "number"
Attribute Values: The scale attribute accepts the values mentioned above and described below
number: It is either an integer or a number with a fractional component. The default value is equal to 0.
The below examples illustrate the use of the scale attribute.
Example 1:
HTML
<!DOCTYPE html><html>  <body>    <div style="color: green;              margin-left: 50px;">          <h1>GeeksforGeeks</h1>          <svg viewBox="0 0 480 100"             xmlns="http://www.w3.org/2000/svg">              <filter id="geek1" x="-20%" y="-20%"                 width="150%" height="150%">                                  <feTurbulence type="turbulence"                     baseFrequency="0.10"                     numOctaves="2"                     result="turbulence" />                  <feDisplacementMap in2="turbulence"                     in="SourceGraphic" scale="5" />            </filter>                          <polygon points="50, 9 60.5, 39.5 92.7,                40.1 67, 59.5 76.4, 90.3 50, 71.9                 23.6, 90.3 32.9, 59.5 7.2, 40.1                 39.4,39.5" style="filter: url(#geek1);"                fill="hsl(106,80%,50%)" />        </svg>    </div></body>  </html>
Output:
Example 2:
HTML
<!DOCTYPE html><html>  <body>    <div style="color: green;              margin-left: 50px;">          <h1>GeeksforGeeks</h1>          <svg viewBox="0 0 480 100"             xmlns="http://www.w3.org/2000/svg">              <filter id="geek2" x="-20%" y="-20%"                 width="150%" height="150%">                                  <feTurbulence type="turbulence"                     baseFrequency="0.05"                     numOctaves="2"                     result="turbulence" />                  <feDisplacementMap in2="turbulence"                     in="SourceGraphic" scale="20" />            </filter>              <polygon points="50, 9 60.5, 39.5 92.7,                40.1 67, 59.5 76.4, 90.3 50, 71.9                 23.6, 90.3 32.9, 59.5 7.2, 40.1                 39.4, 39.5" style="filter: url(#geek2);"                fill="hsl(106,80%,50%)" />        </svg>    </div></body>  </html>
Output:
HTML-SVG
SVG-Attribute
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
REST API (Introduction)
Design a Tribute Page using HTML & CSS
Build a Survey Form using HTML and CSS
Design a web page using HTML and CSS
Angular File Upload
Installation of Node.js on Linux
Difference between var, let and const keywords in JavaScript
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
ulong keyword in C#

22 Jun, 2020
Keywords are the words in a language that are used for some internal process or represent some predefined actions. ulong is a keyword that is used to declare a variable which can store an unsigned integer value from the range 0 to 18,446,744,073,709,551,615. It is an alias of System.UInt64.
ulong keyword occupies 8 bytes (64 bits) space in the memory.
Syntax:
ulong variable_name = value;
Example:
Input: num: 223

Output: num: 223
        Size of a ulong variable: 8

Input: num = 0

Output: Type of num: System.UInt64
        num: 0
        Size of a ulong variable: 8
Note:
If we input number beyond the range, it shows error-Integral constant is too large
Integral constant is too large
If we input wrong value for eg. -34, it shows error-Constant value `-34' cannot be converted to a `ulong'
Constant value `-34' cannot be converted to a `ulong'
// C# program for ulong keyword using System; using System.Text;   class Prog {       static void Main(string[] args)     {         // variable declaration         ulong num = 223;           // to print value         Console.WriteLine("num: " + num);           // to print size         Console.WriteLine("Size of a ulong variable: " + sizeof(ulong));     } } 

Output:
num: 223
Size of a ulong variable: 8

Example 2:
// C# program for ulong keywordusing System;using System.Text;  namespace Test {  class Prog {      static void Main(string[] args)    {        // variable declaration        ulong num = 0;          // to print type of variable        Console.WriteLine("Type of num: " + num.GetType());          // to print value        Console.WriteLine("num: " + num);          // to print size        Console.WriteLine("Size of a ulong variable: " + sizeof(ulong));          // to print minimum & maximum value of ulong        Console.WriteLine("Min value of ulong: " + ulong.MinValue);        Console.WriteLine("Max value of ulong: " + ulong.MaxValue);          // hit ENTER to exit        Console.ReadLine();    }}}
Output:
Type of num: System.UInt64
num: 0
Size of a ulong variable: 8
Min value of ulong: 0
Max value of ulong: 18446744073709551615

CSharp-keyword
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# | Multiple inheritance using interfaces
Differences Between .NET Core and .NET Framework
Extension Method in C#
C# | List Class
C# | .NET Framework (Basic Architecture and Component Stack)
HashSet in C# with Examples
Lambda Expressions in C#
Switch Statement in C#
Partial Classes in C#
Hello World in C#
numpy.unravel_index() function | Python

22 Apr, 2020
numpy.unravel_index() function converts a flat index or array of flat indices into a tuple of coordinate arrays.
Syntax : numpy.unravel_index(indices, shape, order = ‘C’)Parameters :indices : [array_like] An integer array whose elements are indices into the flattened version of an array of dimensions shape.shape : [tuple of ints] The shape of the array to use for unraveling indices.order : [{‘C’, ‘F’}, optional] Determines whether the multi-index should be viewed as indexing in row-major (C-style) or column-major (Fortran-style) order.
Return : [tuple of ndarray] Each array in the tuple has the same shape as the indices array.
Code #1 :
# Python program explaining# numpy.unravel_index() function  # importing numpy as geek import numpy as geek  gfg = geek.unravel_index([22, 41, 37], (7, 6))  print(gfg) 
Output :
(array([3, 6, 6]), array([4, 5, 1]))

 Code #2 :
# Python program explaining# numpy.unravel_index() function  # importing numpy as geek import numpy as geek  gfg = geek.unravel_index([22, 41, 37], (7, 6), order = 'F')  print(gfg) 
Output :
(array([1, 6, 2]), array([3, 5, 5]))

Python numpy-arrayManipulation
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Enumerate() in Python
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
Convert integer to string in Python
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
\varnothing - Tex Command

\varnothing - Used to create varnothing symbol.
{ \varnothing}
\varnothing command draws varnothing symbol.

\varnothing

∅



\varnothing

∅


\varnothing

    14 Lectures 
     52 mins

 Ashraf Said

    11 Lectures 
     1 hours 

 Ashraf Said

    9 Lectures 
     1 hours 

 Emenwa Global, Ejike IfeanyiChukwu

    29 Lectures 
     2.5 hours 

 Mohammad Nauman

    14 Lectures 
     1 hours 

 Daniel Stern

    15 Lectures 
     47 mins

 Nishant Kumar
 Print
 Add Notes
 Bookmark this page
Tryit Editor v3.7

Background Image Repeat
Tryit: Position a background image
Assigning multiple variables in one line in Python - GeeksforGeeks

02 Dec, 2021
A variable is a named memory space that is used to store some data which will in-turn be used in some processing. All programming languages have some mechanism for variable declaration but one thing that stays common in all is the name and the data to be assigned to it. They are capable of storing values of data types.
Assignment operator(=) assigns the value provided to its right to the variable name given to its left. Given is the basic syntax of variable declaration:
Syntax:
var_name = value
Example:
a = 4
Given above is the mechanism for assigning just variables in Python but it is possible to assign multiple variables at the same time. Python assigns values from right to left. When assigning multiple variables in a single line, different variable names are provided to the left of the assignment operator separated by a comma. The same goes for their respective values except they should to the right of the assignment operator.
While declaring variables in this fashion one must be careful with the order of the names and their corresponding value first variable name to the left of the assignment operator is assigned with the first value to its right and so on. 
Example 1:
Python3
a, b = 4, 8print("value assigned to a")print(a)print("value assigned to b")print(b)
Output:
value assigned to a
4
value assigned to b
8
Variable assignment in a single line can also be done for different data types.
Example 2:
Python3
print("assigning values of different datatypes")a, b, c, d = 4, "geeks", 3.14, Trueprint(a)print(b)print(c)print(d)
Output:
assigning values of different datatypes
4
geeks
3.14
True
Not just simple variable assignment, assignment after performing some operation can also be done in the same way.
Example 3:
Python3
a, b = 8, 3add, pro = (a+b), (a*b)print(add)print(pro)
Output:
11
24
Example 4:
Python3
string = "Geeks"a, b, c = string[0], string[1:4], string[4] print(a)print(b)print(c)
Output:
G
eek
s
sweetyty
python-basics
Technical Scripter 2020
Python
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install PIP on Windows ?
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Pandas dataframe.groupby()
Defaultdict in Python
Python | Get unique values from a list
Python Classes and Objects
Python | os.path.join() method
Create a directory in Python
C# program to convert time from 12 hour to 24 hour format

Firstly, set the 12 hr format date.
DateTime d = DateTime.Parse("05:00 PM");
Now let us convert it into 24-hr format.
d.ToString("HH:mm"));
The following is the code to covert time from 12 hour to 24 hour format −
 Live Demo
using System;
namespace Demo {
   public class Program {
      public static void Main(string[] args) {
         DateTime d = DateTime.Parse("05:00 PM");
         Console.WriteLine(d.ToString("HH:mm"));
      }
   }
}
17:00
How to write the plot title in multiple lines using plot function in R?

Mostly, the main title of a plot is short but we might have a long line to write for the main title of the plot. For example, a short version might be “Scatterplot” and a longer version might be “Scatterplot between X and Y”. Therefore, in plot function of R we can use line breaks for the main title as "Scatterplot \n between \n X and Y".
set.seed(123)
x <-rnorm(10)
y <-rnorm(10,2.5)
Creating a simple scatterplot between x and y with main title −
plot(x,y,main="Scatterplot between X and Y")
Creating a simple scatterplot between x and y with main title in multiple lines −
plot(x,y,main="Scatterplot \n between \n X and Y")
Result of comma operator as l-value in C and C++

28 May, 2017
Using result of comma operator as l-value is not valid in C. But in C++, result of comma operator can be used as l-value if the right operand of the comma operator is l-value.
For example, if we compile the following program as a C++ program, then it works and prints b = 30. And if we compile the same program as C program, then it gives warning/error in compilation (Warning in Dev C++ and error in Code Blocks).
#include<stdio.h>  int main(){  int a = 10, b = 20;  (a, b) = 30; // Since b is l-value, this statement is valid in C++, but not in C.  printf("b = %d", b);  getchar();  return 0;}
C++ Output:b = 30
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
C-Operators
C Language
C++
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Substring in C++
Function Pointer in C
Multidimensional Arrays in C / C++
Left Shift and Right Shift Operators in C/C++
Different Methods to Reverse a String in C++
Vector in C++ STL
Map in C++ Standard Template Library (STL)
Initialize a vector in C++ (7 different ways)
Set in C++ Standard Template Library (STL)
vector erase() and clear() in C++
PostgreSQL - NULL Values

The PostgreSQL NULL is the term used to represent a missing value. A NULL value in a table is a value in a field that appears to be blank.
A field with a NULL value is a field with no value. It is very important to understand that a NULL value is different from a zero value or a field that contains spaces.
The basic syntax of using NULL while creating a table is as follows −
CREATE TABLE COMPANY(
   ID INT PRIMARY KEY     NOT NULL,
   NAME           TEXT    NOT NULL,
   AGE            INT     NOT NULL,
   ADDRESS        CHAR(50),
   SALARY         REAL
);

Here, NOT NULL signifies that  column should always accept an explicit value of the given data type. There are two columns where we did not use NOT NULL. Hence, this means these columns could be NULL.

A field with a NULL value is one that has been left blank during record creation.
The NULL value can cause problems when selecting data, because when comparing an unknown value to any other value, the result is always unknown and not included in the final results. Consider the following table, COMPANY having the following records −
ID          NAME        AGE         ADDRESS     SALARY
----------  ----------  ----------  ----------  ----------
1           Paul        32          California  20000.0
2           Allen       25          Texas       15000.0
3           Teddy       23          Norway      20000.0
4           Mark        25          Rich-Mond   65000.0
5           David       27          Texas       85000.0
6           Kim         22          South-Hall  45000.0
7           James       24          Houston     10000.0
Let us use the UPDATE statement to set few nullable values as NULL as follows −
testdb=# UPDATE COMPANY SET ADDRESS = NULL, SALARY = NULL where ID IN(6,7);
Now, COMPANY table should have the following records −
 id | name  | age | address     | salary
----+-------+-----+-------------+--------
  1 | Paul  |  32 | California  |  20000
  2 | Allen |  25 | Texas       |  15000
  3 | Teddy |  23 | Norway      |  20000
  4 | Mark  |  25 | Rich-Mond   |  65000
  5 | David |  27 | Texas       |  85000
  6 | Kim   |  22 |             |
  7 | James |  24 |             |
(7 rows)
Next, let us see the usage of IS NOT NULL operator to list down all the records where SALARY is not NULL −
testdb=#  SELECT  ID, NAME, AGE, ADDRESS, SALARY
   FROM COMPANY
   WHERE SALARY IS NOT NULL;
The above given PostgreSQL statement will produce the following result −
 id | name  | age | address    | salary
----+-------+-----+------------+--------
  1 | Paul  |  32 | California |  20000
  2 | Allen |  25 | Texas      |  15000
  3 | Teddy |  23 | Norway     |  20000
  4 | Mark  |  25 | Rich-Mond  |  65000
  5 | David |  27 | Texas      |  85000
(5 rows)

The following is the usage of  IS NULL operator which will list down all the records where SALARY is NULL −
testdb=#  SELECT  ID, NAME, AGE, ADDRESS, SALARY
        FROM COMPANY
        WHERE SALARY IS NULL;
The above given PostgreSQL statement will produce the following result −
 id | name  | age | address | salary
----+-------+-----+---------+--------
  6 | Kim   |  22 |         |
  7 | James |  24 |         |
Python | fsum() function

18 Sep, 2018
fsum() is inbuilt function in Python, used to find sum between some range or an iterable. To use this function we need to import the math library.
Syntax :
maths.fsum( iterable )

Parameter :
iterable : Here we pass some value
which is iterable like arrays, list.
Use :
fsum() is used to find the sum
of some range, array , list.
Return Type :
The function return a
floating point number.
 
Code demonstrating fsum() :
# Python code to demonstrate use  # of math.fsum() function  # fsum() is found in math libraryimport math  # range(10)print(math.fsum(range(10)))  # Integer listarr = [1, 4, 6]print(math.fsum(arr))  # Floating point listarr = [2.5, 2.4, 3.09]print(math.fsum(arr))
Output :
45.0
11.0
7.99

Python-Functions
python-list
python-list-functions
Python
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python | os.path.join() method
Introduction To PYTHON
Python OOPs Concepts
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Get unique values from a list
Create a directory in Python
How to insert elements in C++ STL List?

Suppose we have one STL list in C++. There are few elements. We have to insert a new element into the list. We can insert at the end, or beginning or at any position. Let us see one code to get better understanding. To insert at beginning we will use push_front(), To insert at end, we will use push_end() and to insert at any position, we have to use some operations. we have to initialize one iterator, then move that iterator to correct position, then insert into that place using insert() method.
 Live Demo
#include<iostream>
#include<list>
using namespace std;
void display(list<int> my_list){
   for (auto it = my_list.begin(); it != my_list.end(); ++it)
   cout << *it << " ";
}
int main() {
   int arr[] = {10, 41, 54, 20, 23, 69, 84, 75};
   int n = sizeof(arr)/sizeof(arr[0]);
   list<int> my_list;
   for(int i = 0; i<n; i++){
      my_list.push_back(arr[i]);
   }
   cout << "List before insertion: ";
   display(my_list);
   //insert 100 at front
   my_list.push_front(100);
   //insert 500 at back
   my_list.push_back(500);
   //insert 1000 at index 5
   list<int>::iterator it = my_list.begin();
   advance(it, 5);
   my_list.insert(it, 1000);
   cout << "\nList after insertion: ";
   display(my_list);
}
List before insertion: 10 41 54 20 23 69 84 75
List after insertion: 100 10 41 54 20 1000 23 69 84 75 500