code-rag-bench/online-tutorials huggingface dataset:
Python – Convert each list element to key-value pair

12 Nov, 2020
Given list of elements, convert each element to a key-value pair dictionary, dividing digits equally.
Input : test_list = [2323, 82, 129388, 234, 95] Output : {23: 23, 8: 2, 129: 388, 2: 34, 9: 5} Explanation : Digits distributed equally to keys and values.
Input : test_list = [2323, 82, 129388] Output : {23: 23, 8: 2, 129: 388} Explanation : Digits distributed equally to keys and values.  
Approach: Using list slicing + loop
In this, we form key-value pair by getting the sliced values from each element by dividing by half the digits for keys and values.
Python3
# Python3 code to demonstrate working of# Convert each list element to key-value pair# Using loop + list slicing  # initializing listtest_list = [2323, 82, 129388, 234, 95]  # printing original listprint("The original list is : " + str(test_list))  res = dict()for ele in test_list:      # constructing key and values    mid_idx = len(str(ele)) // 2    key = int(str(ele)[:mid_idx])    val = int(str(ele)[mid_idx:])      # item assignment    res[key] = val  # printing resultprint("Constructed Dictionary : " + str(res))
The original list is : [2323, 82, 129388, 234, 95]
Constructed Dictionary : {23: 23, 8: 2, 129: 388, 2: 34, 9: 5}

Python dictionary-programs
Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Printing out to the Screen or to a File in R Programming – cat() Function

17 Jun, 2021
cat() function in R Language is used to print out to the screen or to a file. 
Syntax: cat(..., file = “”, sep = ” “, fill = FALSE, labels = NULL, append = FALSE)Parameters: ...: atomic vectors, names, NULL and objects with no output file: the file in which printing will be done sep: specified separator fill: If fill=TRUE, a new line will be printed, otherwise not labels: specified labels  
Example 1:  
Python3
# R program to illustrate# cat function # Creating some string and print itx <- "GeeksforGeeks\n"y <- "Geeks\n" # Calling cat() functioncat(x)cat(y) # Creating a sequence from 1 to 9x <- 1:9 # Calling cat() functioncat(x, sep =" + ")cat("\n")cat(x, sep =" / ")
Output:  
GeeksforGeeks
Geeks
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9
1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9
Example 2:  
Python3
# R program to illustrate# cat function # Creating a sequence from 1 to 9x <- 1:9 # Calling cat() function # fill value TRUE will print# a new linecat(x, sep =" + ", fill = TRUE)cat(x, sep =" / ", fill = FALSE) # Printing new linecat("\n") # Each number from 1 to 9 will be# assigned with alphabets a to icat(x, fill = 2, labels = paste("(", letters[1:9], "):"))        
Output:  
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9
1 / 2 / 3 / 4 / 5 / 6 / 7 / 8 / 9
( a ): 1 
( b ): 2 
( c ): 3 
( d ): 4 
( e ): 5 
( f ): 6 
( g ): 7 
( h ): 8 
( i ): 9
 
arorakashish0911
sweetyty
R String-Functions
R-strings
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
How to Split Column Into Multiple Columns in R DataFrame?
Group by function in R using Dplyr
How to Change Axis Scales in R Plots?
R - if statement
How to filter R DataFrame by values in a column?
Logistic Regression in R Programming
Replace Specific Characters in String in R
How to import an Excel File into R ?
Joining of Dataframes in R Programming
Conversion of Array To ArrayList in Java



We can convert an array to arraylist using following ways.
Using Arrays.asList() method - Pass the required array to this method and get a List object and pass it as a parameter to the constructor of the ArrayList class.
Using Arrays.asList() method - Pass the required array to this method and get a List object and pass it as a parameter to the constructor of the ArrayList class.
Collections.addAll() method - Create a new list before using this method and then add array elements using this method to existing list.
Collections.addAll() method - Create a new list before using this method and then add array elements using this method to existing list.
Iteration method - Create a new list. Iterate the array and add each element to the list.
Iteration method - Create a new list. Iterate the array and add each element to the list.
Live Demo
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Tester {
   public static void main(String args[]) {
      String[] array = {"a", "b", "c", "d", "e"};

      //Method 1
      List<String> list = Arrays.asList(array);          
      System.out.println(list);

      //Method 2
      List<String> list1 = new ArrayList<String>();
      Collections.addAll(list1, array);
      System.out.println(list1);

      //Method 3
      List<String> list2 = new ArrayList<String>();
      for(String text:array) {
         list2.add(text);
      }
      System.out.println(list2);
   }  
}
[a, b, c, d, e]
[a, b, c, d, e]
[a, b, c, d, e]
How to find the int value of a string in Python?

01 Aug, 2020
In Python, we can represent an integer value in the form of string. Int value of a string can be obtained by using inbuilt function in python called as int(). Here we can pass string as argument to this function which returns int value of a string.
Syntax : int(string, base)Parameters :
string : consists of 1’s and 0’s
base : (integer value) base of the number.
Returns : an integer value, which is equivalent of binary string in the given base.TypeError : Returns TypeError when any data type otherthan string or integer is passed in its equivalent position.
By default, int() assumes the number to be in decimal notation. If we want a string representation of int which belongs to other number systems like binary, hexadecimal, octal. We need to pass an extra argument to this function specifying the base value. The base values are :
binary : 2
octal : 8
hexadecimal : 16
Examples :
Input : "A"  (for base 16)
Output : 10

Input : "510"
Output : 510

# using base 16s1 = "A"print(int(s1, 16))  # using the default bases2 = "510"print(int(s2))
Output :
10
510

python-basics
Python-Built-in-functions
Python
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 OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Python | os.path.join() method
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Create a directory in Python
Python | Accessing all elements at given list of indexes

02 Dec, 2018
Accessing an element from its index is easier task in python, just using the [] operator in a list does the trick. But in certain situations we are presented with tasks when we have more than once indices and we need to get all the elements corresponding to those indices. Lets discuss certain ways to achieve this task.
Input : list = [9, 4, 5, 8, 10, 14]
        index_list = [1, 3, 4]
Output : 4 8 10

Method #1 : Using List comprehensionThis task is easy to perform with a loop, and hence shorthand for it is the first method to start with this task. Iterating over the index list to get the corresponding elements from list into new list is brute method to perform this task.
# Python3 code to demonstrate # to get elements from indices# using list comprehension  # initializing liststest_list = [9, 4, 5, 8, 10, 14]index_list = [1, 3, 4]  # printing original listsprint ("Original list : " + str(test_list))print ("Original index list : " + str(index_list))  # using list comprehension to # elements from list res_list = [test_list[i] for i in index_list]      # printing resultprint ("Resultant list : " + str(res_list))
Output :
Original list : [9, 4, 5, 8, 10, 14]
Original index list : [1, 3, 4]
Resultant list : [4, 8, 10]

Method #2 : Using map() + __getitem__Yet another method to achieve this particular task is to map one list with other and get items of indexes and get corresponding matched elements from the search list. This is quite quick way to perform this task.
# Python3 code to demonstrate # to get elements from indices# using map() + __getitem__  # initializing liststest_list = [9, 4, 5, 8, 10, 14]index_list = [1, 3, 4]  # printing original listsprint ("Original list : " + str(test_list))print ("Original index list : " + str(index_list))  # using map() + __getitem__ to # elements from list res_list = map(test_list.__getitem__, index_list)      # printing resultprint ("Resultant list : " + str(res_list))
Output :
Original list : [9, 4, 5, 8, 10, 14]
Original index list : [1, 3, 4]
Resultant list : [4, 8, 10]

Method #3 : Using operator.itemgetter()This technique is most pythonic and elegant method to perform this particular task. This function zips the elements of the original list with the index required from the other, hence the fasted method to achieve this task.
# Python3 code to demonstrate # to get elements from indices# using operator.itemgetter()from operator import itemgetter  # initializing liststest_list = [9, 4, 5, 8, 10, 14]index_list = [1, 3, 4]  # printing original listsprint ("Original list : " + str(test_list))print ("Original index list : " + str(index_list))  # using operator.itemgetter() to # elements from list res_list = list(itemgetter(*index_list)(test_list))      # printing resultprint ("Resultant list : " + str(res_list))
Output :
Original list : [9, 4, 5, 8, 10, 14]
Original index list : [1, 3, 4]
Resultant list : [4, 8, 10]

Python list-programs
python-list
Python
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to create an HTML element using jQuery ?

21 Sep, 2021
In this article, we will see how to create an HTML element using jQuery. To create and append HTML element, we use jQuery append() method. 
The jQuery append() method is used to insert some content at the end of the selected elements.
Syntax:
$(selector).append( content, function(index, html) )
Parameters:
content: It is required parameter and used to specify the content which is to be inserted at the end of selected elements. The possible value of contents are HTML elements, jQuery objects and DOM elements.
function(index, html): It is optional parameter and used to specify the function that will return the content to be inserted.index: It is used to return the index position of the element.html: It is used to return the current HTML of the selected element.
index: It is used to return the index position of the element.
html: It is used to return the current HTML of the selected element.
Example:
HTML
<!DOCTYPE html><html>  <head>    <title>        How to create an HTML element using jQuery?    </title>      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">    </script>      <!-- Script to add div element in the HTML document -->    <script>        $(document).ready(function() {              $("button").click(function() {                $(".append").append('<div class="added">New HTML element added</div>');            });        });    </script>      <!-- Style to use on div element -->    <style>        .added {            padding: 20px;            margin-top: 20px;            background: green;            color: white;            display: inline-block;        }    </style></head>  <body>    <center>        <h1 style="color: green;">GeeksforGeeks</h1>          <h3>            How to create an HTML element using jQuery?        </h3>          <button id="append">Append New HTML Element</button>          <div class="append"></div>    </center></body>  </html>
Output:
CSS-Properties
HTML-Questions
jQuery-Methods
jQuery-Questions
Picked
CSS
HTML
JQuery
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Design a Tribute Page using HTML & CSS
How to set space between the flexbox ?
Build a Survey Form using HTML and CSS
Design a web page using HTML and CSS
Form validation using jQuery
REST API (Introduction)
Hide or show elements in HTML using display property
How to set the default value for an HTML <select> element ?
How to set input type date in dd-mm-yyyy format using HTML ?
Design a Tribute Page using HTML & CSS
C++ Array Library - operator[] Function

The C++ function std::array::operator[] returns reference to the element present at location n in a given array container. This method doesn't check for array bounds. Accessing element other than valid array bounds will cause undefined behavior.
Following is the declaration for std::array::operator[] function form std::array header.
reference operator[](size_type n);
const_reference operator[](size_type n) const;
n − index of the element in array.
Return a reference to the element present at location n in a given array
container.
If array object is const-qualified the method returns const reference, otherwise
it return reference.
This member function never throws exception if value of n is valid array index,
otherwise behavior is undefined.
Constant i.e. O(1)
The following example shows the usage of std::array::operator[] function.
#include <iostream>
#include <array>

using namespace std;

int main(void) {

   array<int, 5> arr = {1, 2, 3, 4, 5};

   /* iterator array using [] operator */
   for (size_t i = 0; i < 5; ++i)
      cout << arr[i] << " ";
   cout << endl;

   /* assing new value to the first array element */
   arr[0] = 10;

   /* print modified array */
   for (size_t i = 0; i < 5; ++i)
      cout << arr[i] << " ";
   cout << endl;

   return 0;
}
Let us compile and run the above program, this will produce the following result −
1 2 3 4 5 
10 2 3 4 5 

 Print
 Add Notes
 Bookmark this page
Bootstrap navbar-inverse class

To create an inverted navbar with a black background and with white text, simply add the .navbar-inverse class to the .navbar class.
You can try to run the following code to implement navbar-inverse class −
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <nav class = "navbar navbar-inverse" role = "navigation">
         <div class = "navbar-header">
            <a class = "navbar-brand" href = "#">TutorialsPoint</a>
         </div>
         <div>
            <ul class = "nav navbar-nav">
               <li class = "active"><a href = "#">iOS</a></li>
               <li><a href = "#">SVN</a></li>
               <li class = "dropdown">
                  <a href = "#" class = "dropdown-toggle" data-toggle = "dropdown">
                     Java
                     <b class = "caret"></b>
                  </a>
                  <ul class = "dropdown-menu">
                     <li><a href = "#">jmeter</a></li>
                     <li><a href = "#">EJB</a></li>
                     <li><a href = "#">Jasper Report</a></li>
                     <li class = "divider"></li>
                     <li><a href = "#">Separated link</a></li>
                     <li class = "divider"></li>
                     <li><a href = "#">One more separated link</a></li>
                  </ul>
               </li>
            </ul>
         </div>
      </nav>
   </body>
</html>
Java Program to print Number series without using any loop

Following is the Java code to print Number srries without using any loop −
 Live Demo
public class Demo{
   public static void main(String[] args){
      int my_num = 0;
      System.out.println("The numbers without using loop have been printed below");
      print_without_loop(my_num);
   }
   public static void print_without_loop(int my_num){
      if(my_num <= 15){
         System.out.print(my_num +",");
         print_without_loop(my_num + 1);
      }
   }
}
The numbers without using loop have been printed below
0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,
A class named Demo contains the main function where a variable named ‘my_num’ is initialized to 0. A function named ‘print_without_loop’ is called. It is defined further wherein condition is checked if the number passedis greater than 15, if yes, then the number is printed beginning from 0 and incrementing it after every pass. Once the element 15 is reached, the condition exits.
How to create table border in HTML?

To create table border in HTML, the border attribute was used. But the introduction of HTML5, deprecated the border tag. Create table border using the CSS property border. Set table border as well as border for <th> and <td>.
You can try to run the following code to create a border in the table in HTML. We’re using <style> tag here:
<!DOCTYPE html>
<html>
   <head>
      <style>
         table, th, td {
            border: 1px solid black;
         }
      </style>
   </head>
   <body>
      <h1>Employee Details</h1>
      <table>
         <tr>
            <th>Name</th>
            <td>Amit</td>
            <td>Sachin</td>
         </tr>
         <tr>
            <th>Age</th>
            <td>27</td>
            <td>34</td>
         </tr>
      </table>
   </body>
</html>
How to have a structure with a table in ABAP?

The basic rule while specifying a table within a structure is that you have to give a non-unique constraint to that field.
TYPES: myType TYPE TABLE OF string WITH NON-UNIQUE DEFAULT KEY
Then use this in the structure definition:
TYPES: BEGIN OF ty_itab,
.....
myTable type myType,
........
TYPES: END OF ty_itab.
Javascript | Window prompt() Method - GeeksforGeeks

26 Jul, 2019
The prompt() method is used to display a dialog with an optional message prompting the user to input some text. It is often used if the user wants to input a value before entering a page.It returns a string containing the text entered by the user, or null.
Syntax:
prompt(message, default)

message is a string of text to display to the user.It can be omitted if there is nothing to show in the prompt window i.e. it is optional.
default is a string containing the default value displayed in the text input field. It is also optional.
Example:
<!DOCTYPE html><html>  <head>    <title>        Window prompt() Method    </title></head>  <body style="text-align: center;">    <h1 style="color:green;">        GeeksforGeeks    </h1>    <h2>        Window prompt() Method    </h2>      <button onclick="geek()">        Click me!    </button>    <p id="g"></p>      <script>        function geek() {            var doc = prompt("Please enter some text",                "GeeksforGeeks");            if (doc != null) {                document.getElementById("g").innerHTML =                    "Welcome to " + doc;            }        }    </script></body>  </html>
Output:Before clicking the button:
After clicking the Click me! button:
After pressing the OK button in dialog box:
Supported Browsers: The browser supported by window prompt() method are listed below:
Google Chrome
Internet Explorer
Firefox
Opera
Safari
Vishal Chaudhary 2
javascript-functions
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to append HTML code to a div using JavaScript ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Tryit Editor v3.7

Tryit: The transition-delay property
How to get unique values from MongoDB collection?

To get unique values and ignore duplicates, use distinct() in MongoDB. The distinct() finds the distinct values for a specified field across a single collection and returns the results in an array.
Let us create a collection with documents −
> db.demo704.insertOne({"LanguageCode":"hi"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5ea6ee18551299a9f98c93bd")
}
> db.demo704.insertOne({"LanguageCode":"en"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5ea6ee1e551299a9f98c93be")
}
> db.demo704.insertOne({"LanguageCode":"hi"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5ea6ee20551299a9f98c93bf")
}
> db.demo704.insertOne({"LanguageCode":"eo"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5ea6ee2c551299a9f98c93c0")
}
> db.demo704.insertOne({"LanguageCode":"eu"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5ea6ee2f551299a9f98c93c1")
}
> db.demo704.insertOne({"LanguageCode":"fo"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5ea6ee35551299a9f98c93c2")
}
> db.demo704.insertOne({"LanguageCode":"fo"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5ea6ee37551299a9f98c93c3")
}
Display all documents from a collection with the help of find() method −
> db.demo704.find();
This will produce the following output −
{ "_id" : ObjectId("5ea6ee18551299a9f98c93bd"), "LanguageCode" : "hi" }
{ "_id" : ObjectId("5ea6ee1e551299a9f98c93be"), "LanguageCode" : "en" }
{ "_id" : ObjectId("5ea6ee20551299a9f98c93bf"), "LanguageCode" : "hi" }
{ "_id" : ObjectId("5ea6ee2c551299a9f98c93c0"), "LanguageCode" : "eo" }
{ "_id" : ObjectId("5ea6ee2f551299a9f98c93c1"), "LanguageCode" : "eu" }
{ "_id" : ObjectId("5ea6ee35551299a9f98c93c2"), "LanguageCode" : "fo" }
{ "_id" : ObjectId("5ea6ee37551299a9f98c93c3"), "LanguageCode" : "fo" }
Following is the query to get unique values and display the result in an array −
> db.demo704.distinct("LanguageCode");
This will produce the following output −
[ "hi", "en", "eo", "eu", "fo" ]
What are destructors in C# programs?

A destructor is a special member function of a class that is executed whenever an object of its class goes out of scope.
It has exactly the same name as that of the class with a prefixed tilde (~), for example, our class name is Demo.
public Demo() { // constructor
   Console.WriteLine("Object is being created");
}
~Demo() { //destructor
   Console.WriteLine("Object is being deleted");
}
Let us see an example to learn how to work with Destructor in C#.
 Live Demo
using System;

namespace LineApplication {
   class Line {
      private double length; // Length of a line

      public Line() { // constructor
         Console.WriteLine("Object is being created");
      }

      ~Line() { //destructor
         Console.WriteLine("Object is being deleted");
      }

      public void setLength( double len ) {
         length = len;
      }

      public double getLength() {
         return length;
      }

      static void Main(string[] args) {
         Line line = new Line();
     
         // set line length
         line.setLength(6.0);
         Console.WriteLine("Length of line : {0}", line.getLength());
      }
   }
}
Object is being created
Length of line : 6
Object is being deleted
Bootstrap 4 .flex-row-reverse class

Use the flex-row-reverse class in Bootstrap to reverse the order of flex items. It also aligns the flex items to the right.
Let us see the difference between the default arrangement of flex items and result of row-reverse class −
For reversing the order of rows, we have used the flex-row-reverse class like the following code snippet:
<div class="d-flex flex-row-reverse bg-primary mb-3">
The following is an example to implement the flex-row-reverse class −
Live Demo
<!DOCTYPE html>
<html>
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  </head>

<body>
  <div class="container mt-3">
    <h2>Flex</h2>
    <h2>Flex Row Reverse</h2>
    <div class="d-flex flex-row-reverse bg-primary mb-3">
      <div class="p-2 bg-secondary">A-ONE</div>
      <div class="p-2 bg-warning">B-ONE</div>
      <div class="p-2 bg-info">C-ONE</div>
    </div>
    <h2>Flex Row </h2>
      <div class="d-flex flex-row bg-primary mb-3">
      <div class="p-2 bg-secondary">A-ONE</div>
      <div class="p-2 bg-warning">B-ONE</div>
      <div class="p-2 bg-info">C-ONE</div>
  </div>
</div>
</body>
</html>
Python program to count occurrences of an element in a tuple

Here given a user input tuple, our task is to count occurrences of a given element in a tuple.
Input : A = [10, 20, 30, 40, 10, 100, 80, 10]
        X = 10
Output : 3

countoccur(A,x)
/* A is an array and x is the element to count the number of occurrences */
Step 1: First we use one counter variable which is count the same element.
Step 2: Then traverse the tuple.
Step 3: Then check x with every element of the tuple.
Step 4: If the element is matched with the x, then counter is incremented by 1.
Step 5: Return counter variable.

# Program to count occurrences of an element in a tuple 

def countoccur(A, x): 
   c = 0
   for i in A: 
      if (i == x): 
         c = c + 1
   return c 

# Driver Code
A=list()
n1=int(input("Enter the size of the List ::"))
print("Enter the Element of List ::")
for i in range(int(n1)):
   k=int(input(""))
   A.append(k)
n=int(input("Enter an element to count number of occurrences ::"))       
print("Number of Occurrences of ",n,"is",countoccur(A, n)) 
Enter the size of the List ::6
Enter the Element of List ::
12
23
45
12
89
12
Enter an element to count number of occurrences :12
Number of Occurrences of 12 is 3
Importing data into models in Django

In this article, we are going to see how to import data from json format to model. We can import data from json, csv, xlsx, yml, etc. to model.
First of all, create a Django project and an app. Set up urls and do some basic stuff like adding the app in INSTALLED_APPS.
Create a model. Here, we don't have much to do with views.py, urls.py or any html file. We only have to work with settings.py, admin.py, models.py and admin urlpoint.
Install the django-import-export package −
pip install django-import-export
In settings.py, add the following line −
INSTALLED_APPS += ['import_export']
It will add import_export as an app in our project.
Create a model −
class StudentData(models.Model):
   name=models.CharField(max_length=100)
   standard=models.CharField(max_length=100)
   section=models.CharField(max_length=100)
We created the model for testing and trying.
In admin.py −
from django.contrib import admin
from .models import StudentData
from import_export import resources
from import_export.admin import ImportExportModelAdmin

class StudentResource(resources.ModelResource):
   class Meta:
      model = StudentData
class StudentAdmin(ImportExportModelAdmin):
   resource_class = StudentResource

admin.site.register(StudentData,StudentAdmin)
Here we created a model resource for import and export. Then, we created an admin and registered it.
File format for JSON should be like this −
[
   {
      "id": 13,
      "name": "John",
      "standard":"10",
      "section": "B",
      "the_json": {"name":"Jhon"}
   }
]
Field name as key and its value. On Notepad, make a file and save it with the name import_example.json.
Now just import the JSON file import_example.json and your data will be imported in Django model.
The fcntl and ioctl System Calls in Python

To control the files and the io, we should use the fcntl module. It is basically one interface to the fcntl() and ioctl() Unix routines.
All methods in this module takes one integer or io.IOBase file-descriptor as their first argument.
To use this module, we should import it using.
import fcntl

There are some modules of the fcntl module, these are −
This method is used to perform the operation on the file using file descriptor. The operation is defined by op. The third argument is optional. It can be either integer type value or string type value. When the argument is integer type, the return value will be the value of C fcntl() call. When it is string, it represents binary structure. When this function fails, it raises an IOError.
This method is identical to the fcntl() method, but in this case the argument handling is more complex. In the argument, if the mutable buffer is passed, then its behavior will depend on the mutate_flag. When it is true, the buffer can be mutable, otherwise it will act like read-only buffer.
This method is used to perform lock operation op on the file using file_descriptor. On some systems, this method can be emulated using the fcntl() method.
This method is used to perform as a wrapper around the locking calls. The operation argument is passed to lock or unlock the file. There are different values of operation.
LOCK_UN − To unlock the file
LOCK_UN − To unlock the file
LOCK_SH − Shared Lock
LOCK_SH − Shared Lock
LOCK_EX − Exclusive Lock
LOCK_EX − Exclusive Lock
 Live Demo
import fcntl, os, time
counter_file = 'my_counter.txt'
if not os.path.exists(counter_file):
   counter_file = open('my_counter.txt', 'w')
   counter_file.write('0') #Store 0 as starting number
   counter_file.close()
for i in range(15):
   counter_file = open('my_counter.txt', 'r+')
   fcntl.flock(counter_file.fileno(), fcntl.LOCK_EX)
   count = int(counter_file.readline()) + 1
   counter_file.seek(0)
   counter_file.write(str(count))
   counter_file.close()
   print('Process ID: ' + str(os.getpid()) + ', Count: ' + str(count))
   time.sleep(0.2)
$ python3 example.py
Process ID: 12698, Count: 1
Process ID: 12698, Count: 2
Process ID: 12698, Count: 3
Process ID: 12698, Count: 4
Process ID: 12698, Count: 5
Process ID: 12698, Count: 6
Process ID: 12698, Count: 7
Process ID: 12698, Count: 8
Process ID: 12698, Count: 9
Process ID: 12698, Count: 10
Process ID: 12698, Count: 11
Process ID: 12698, Count: 12
Process ID: 12698, Count: 13
Process ID: 12698, Count: 14
Process ID: 12698, Count: 15
$
$
$ cat my_counter.txt
15
$
Assigning debug roles to few users of SAP ABAP program

Hope the role that you have added contains only one permission:
Object S_DEVELOP
   ACTVT = 03
   DEVCLASS = *
   OBJNAME = *
   OBJTYPE = DEBUG
   P_GROUP = *
Try to perform a permission trace usingTransaction ST01
If you still don’t find a check for the permission, there might be a problem in generating roles in the system. Sometimes when you add a role, it might add a different set of roles to such users.There might be a different program written for Debugging. This can be checked using Transaction SU53 in the system. This can be used to display authorization data for user:
Class getPackageName() method in Java with Examples - GeeksforGeeks

27 Jan, 2022
The getPackageName() method of java.lang.Class class is used to get the package name of this entity. This entity can be a class, an array, an interface, etc. The method returns the package name of this entity as a String.Syntax:  
public String getPackageName()
Parameter: This method does not accept any parameter.Return Value: This method returns the package name of this entity as a String.Below programs demonstrate the getPackageName() method.Note: This method was introduced in Java 9. Hence to run this method, we need a compiler with Java 9. So this won’t run in the online IDE.Example 1: 
Java
// Java program to demonstrate getPackageName() method public class Test {    public static void main(String[] args)        throws ClassNotFoundException    {         // returns the Class object for this class        Class myClass = Class.forName("Test");         System.out.println("Class represented by myClass: "                           + myClass.toString());         // Get the package name of myClass        // using getPackageName() method        System.out.println("PackageName of myClass: "                           + myClass.getPackageName());    }}
Output:  
Class represented by myClass: class Test
PackageName of myClass: 
Example 2: 
Java
// Java program to demonstrate getPackageName() method public class Test {     class Arr {    }     public static void main(String[] args)        throws ClassNotFoundException    {        // returns the Class object        Class myClass = Class.forName("java.lang.String");         // Get the package name of myClass        // using getPackageName() method        System.out.println("PackageName of myClass: "                           + myClass.getPackageName());    }}
Output:  
Class represented by myClass: class java.lang.String
PackageName of myClass: java.lang
Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#getPackageName– 
adnanirshad158
Java-Functions
Java-lang package
Java.lang.Class
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Hashtable in Java
Constructors in Java
Different ways of Reading a text file in Java
Comparator Interface in Java with Examples
HashMap containsKey() Method in Java
Difference between Abstract Class and Interface in Java
final Keyword in Java
How to Create Array of Objects in Java?
Java Math random() method with Examples
Java | Implementing Iterator and Iterable Interface
GATE | GATE CS 2008 | Question 67

14 Feb, 2018
A processor uses 36 bit physical addresses and 32 bit virtual addresses, with a page frame size of 4 Kbytes. Each page table entry is of size 4 bytes. A three level page table is used for virtual to physical address translation, where the virtual address is used as follows• Bits 30-31 are used to index into the first level page table• Bits 21-29 are used to index into the second level page table• Bits 12-20 are used to index into the third level page table, and• Bits 0-11 are used as offset within the pageThe number of bits required for addressing the next level page table (or page frame) in the page table entry of the first, second and third level page tables are respectively.
(A) 20, 20 and 20(B) 24, 24 and 24(C) 24, 24 and 20(D) 25, 25 and 24Answer: (D)Explanation: Virtual address size = 32 bits
Physical address size = 36 bits
Physical memory size = 2^36 bytes
Page frame size = 4K bytes = 2^12 bytes
No. of bits for offset (or number of bits required for accessing location within a page frame) = 12.
No. of bits required to access physical memory frame = 36 – 12 = 24
So in third level of page table, 24 bits are required to access an entry.
9 bits of virtual address are used to access second level page table entry and size of pages in second level is 4 bytes. So size of second level page table is (2^9)*4 = 2^11 bytes. It means there are (2^36)/(2^11) possible locations to store this page table. Therefore the second page table requires 25 bits to address it.
Similarly, the first page table needs 25 bits to address it.
Quiz of this Question
GATE-CS-2008
GATE-GATE CS 2008
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Extract a Column from R DataFrame to a List ?

15 Aug, 2021
In this article, we will discuss how to extract a column from a DataFrame to a List in R Programming Language.
In this method, we are going to create a vector with character (names) and integer(marks) type data and passing to the student dataframe. Similarly, we will pass these two vectors to the list and display them.
Syntax:
list(col1, col2,... ,col n)
Example:
R
# vector with namesnames=c("bobby","pinkey","rohith","gnanu") # vector with marksmarks=c(78,90,100,100) # pass these vectors as inputs# to the dataframestudent=data.frame(names,marks) print(student)print("----------------") # pass those vectors to liststudent_list=list(names,marks)print(student_list)
Output:
$ operator in R is used to extract a specific part of data or access a variable in a dataset. We can pass data frame column to a list by using $ operator. The columns to be selected are to be passed with dataframe name separated by $.
Syntax:
list(dataframe$column_name)
Example:
R
# vector with namesnames=c("bobby","pinkey","rohith","gnanu") # vector with marksmarks=c(78,90,100,100) # pass these vectors as inputs# to the dataframestudent=data.frame(names,marks)print(student)print("----------------") # pass marks column  to listprint(list(student$marks))
Output:
We can extract more than one column using the same approach and then again pass it to the list() function.
Example:
R
# vector with namesnames=c("bobby","pinkey","rohith","gnanu") # vector with marksmarks=c(78,90,100,100) # pass these vectors as inputs# to the dataframestudent=data.frame(names,marks)print(student)print("----------------") # pass all columns  to lista=list(student$names,student$marks)print(a)
Output:
Example :
R
# Creating a listexample_list <- list(P = 1:8,                       Q = letters[1:8],                R = 5)example_list # Extracting the values of Q only using $ operatorexample_list$Q
Output :
We can extract elements from a specific column in a list.
mishrapratikshya12
Picked
R DataFrame-Programs
R List-Programs
R-DataFrame
R-List
R Language
R Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Filter data by multiple conditions in R using Dplyr
Printing Output of an R Program
Group by function in R using Dplyr
How to Replace specific values in column in R DataFrame ?
How to filter R DataFrame by values in a column?
How to Replace specific values in column in R DataFrame ?
How to filter R DataFrame by values in a column?
How to change Row Names of DataFrame in R ?
How to Split Column Into Multiple Columns in R DataFrame?
Replace Specific Characters in String in R
Python | CMY and CMYK Color Models

02 Aug, 2019
RGB and HSV, two commonly used color models are discussed in the articles: RGB, HSV. In this article, we introduce the CMY and CMYK color models.
Cyan, magenta and yellow are the secondary colors of light and the primary colors of pigments. This means, if white light is shined on a surface coated with cyan pigment, no red light is reflected from it. Cyan subtracts red light from white light. Unlike the RGB color model, CMY is subtractive, meaning higher values are associated with darker colors rather than lighter ones.
Devices that deploy pigments to color paper or other surfaces use the CMY color model, e.g. printers and copiers. The conversion from RGB to CKY is a simple operation, as is illustrated in the Python program below. It is important that all color values be normalized to [0, 1] before converting.
C = 1 - R
M = 1 - G
Y = 1 - B

Below is the code to convert RGB to CMY color model.
# Formula to convert RGB to CMY.def rgb_to_cmy(r, g, b):      # RGB values are divided by 255     # to bring them between 0 to 1.    c = 1 - r / 255    m = 1 - g / 255    y = 1 - b / 255    return (c, m, y)  # Sample RGB values.r = 0g = 169b = 86  # Print the result.print(rgb_to_cmy(r, g, b))
Output:
(1.0, 0.33725490196078434, 0.6627450980392157)

According to the color wheel shown above, equal amounts of cyan, magenta, and yellow should produce black. However, in real life, combining these pigments produces a muddy-colored black. To produce pure black, which is quite commonly used while printing, we add a fourth color — black, to the pigment mixture. This is called four-color printing. The addition of black in this model results in it being referred to as the CMYK color model.
computer-graphics
Image-Processing
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
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
Introduction To PYTHON
Fix MySQL ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key

To fix this error, you need to add PRIMARY KEY to auto_increment field. Let us now see how this error occurs −
Here, we are creating a table and it gives the same error −
mysql> create table DemoTable
(
   StudentId int NOT NULL AUTO_INCREMENT,
   StudentName varchar(40),
   StudentAge int
);
ERROR 1075 (42000) : Incorrect table definition; there can be only one auto column and it must be defined as a key
To solve the above error, you need to add PRIMARY KEY with AUTO_INCREMENT. Let us first create a table −
mysql> create table DemoTable
(
   StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
   StudentName varchar(40),
   StudentAge int
);
Query OK, 0 rows affected (1.01 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable(StudentName,StudentAge) values('Chris Brown',19);
Query OK, 1 row affected (0.30 sec)
mysql> insert into DemoTable(StudentName,StudentAge) values('David Miller',18);
Query OK, 1 row affected (0.20 sec)
mysql> insert into DemoTable(StudentName,StudentAge) values('John Doe',20);
Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement :
mysql> select *from DemoTable;
This will produce the following output −
+-----------+--------------+------------+
| StudentId | StudentName  | StudentAge |
+-----------+--------------+------------+
|         1 | Chris Brown  |         19 |
|         2 | David Miller |         18 |
|         3 | John Doe     |         20 |
+-----------+--------------+------------+
3 rows in set (0.00 sec)
Python | Generate successive element difference list

23 Dec, 2018
While working with python, we usually come by many problems that we need to solve in day-day and in development. Specially in development, small tasks of python are desired to be performed in just one line. We discuss some ways to compute a list consisting of elements that are successive difference in the list.
Method #1 : Using list comprehensionNaive method can be used to perform, but as this article discusses the one liner solutions to this particular problem, we start with the list comprehension as a method to perform this task.
# Python3 code to demonstrate # to generate successive difference list # using list comprehension  # initializing list test_list = [1, 4, 5, 3, 6]    # printing original list print ("The original list is : " + str(test_list))  # using list comprehension# generate successive difference listres = [test_list[i + 1] - test_list[i] for i in range(len(test_list)-1)]  # printing resultprint ("The computed successive difference list is : " + str(res))
Output :
The original list is : [1, 4, 5, 3, 6]
The computed successive difference list is : [3, 1, -2, 3]

Method #2 : Using zip()zip() can also be used to perform the similar task and uses the power of negative indices to zip() the index element with its next element and hence compute the difference.
# Python3 code to demonstrate # to generate successive difference list # using zip()  # initializing list test_list = [1, 4, 5, 3, 6]  # printing original list print ("The original list is : " + str(test_list))  # using zip()# generate successive difference listres = [j - i for i, j in zip(test_list[: -1], test_list[1 :])]  # printing resultprint ("The computed successive difference list is : " + str(res))
Output :
The original list is : [1, 4, 5, 3, 6]
The computed successive difference list is : [3, 1, -2, 3]

Method #3 : Using map() + operator.submap() can be coupled with the subtraction operator to perform this particular task. This maps the element with its next element and performs the subtraction operation. Other operators can be passed to perform the desired operations.
# Python3 code to demonstrate # to generate successive difference list # using map() + operator.subimport operator  # initializing list test_list = [1, 4, 5, 3, 6]  # printing original list print ("The original list is : " + str(test_list))  # using map() + operator.sub# generate successive difference listres = list(map(operator.sub, test_list[1:], test_list[:-1]))  # printing resultprint ("The computed successive difference list is : " + str(res))
Output :
The original list is : [1, 4, 5, 3, 6]
The computed successive difference list is : [3, 1, -2, 3]

Python list-programs
python-list
Python
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between Fetch and Axios.js for making http requests

16 Jul, 2021
One of the fundamental tasks of any web application is to communicate with servers through the HTTP protocol. This can be easily achieved using Fetch or Axios. Fetch and Axios are very similar in functionality. Some developers prefer Axios over built-in APIs for its ease of use. The Fetch API is perfectly capable of reproducing the key features of Axios.Fetch: The Fetch API provides a fetch() method defined on the window object. It also provides a JavaScript interface for accessing and manipulating parts of the HTTP pipeline (requests and responses). The fetch method has one mandatory argument- the URL of the resource to be fetched. This method returns a Promise that can be used to retrieve the response of the request.  
Program:  
javascript
fetch('path-to-the-resource-to-be-fetched')  .then((response) => {     // Code for handling the response  })  .catch((error) => {     // Code for handling the error  });
Axios: Axios is a Javascript library used to make HTTP requests from node.js or XMLHttpRequests from the browser and it supports the Promise API that is native to JS ES6. It can be used intercept HTTP requests and responses and enables client-side protection against XSRF. It also has the ability to cancel requests.  
Program:  
javascript
axios.get('url')  .then((response) => {     // Code for handling the response  })  .catch((error) => {     // Code for handling the error  })
Differences between Axios and Fetch:  
 
nidhi_biet
kalrap615
ES6
react-js
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Node.js fs.writeFile() Method
How to install the previous version of node.js and npm ?
Difference between promise and async await in Node.js
Mongoose | findByIdAndUpdate() Function
JWT Authentication with Node.js
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React
Online XML Minifier

Editable XML Code
123456789101112131415<?xml version="1.0"?><Company><Employee><FirstName>Tanmay</FirstName><LastName>Patil</LastName><ContactNo>1234567890</ContactNo><Email>tanmaypatil@xyz.com</Email><Address><City>Bangalore</City><State>Karnataka</State><Zip>560212</Zip></Address></Employee></Company>X
Privacy Policy
Cookies Policy
Terms of Use
Java Math acos() method with Examples

05 Apr, 2018
The java.lang.Math.acos() returns the arc cosine of an angle in between 0.0 and pi. Arc cosine is also called as inverse of a cosine.If the argument is NaN or its absolute value is greater than 1, then the result is NaN.
Syntax :
public static double acos(double a)
Parameter :
a : the value whose arc cosine is to be returned.
Return :
This method returns the arc cosine of the argument.
Example :To show working of java.lang.Math.acos() method.
// Java program to demonstrate working// of java.lang.Math.acos() methodimport java.lang.Math;  class Gfg {      // driver code    public static void main(String args[])    {        double a = Math.PI;          // Output is NaN, because Math.PI gives 3.141 value        // greater than 1        System.out.println(Math.acos(a));          // convert Math.PI to radians        double b = Math.toRadians(a);          System.out.println(Math.acos(b));          double c = 1.0;        double d = 0.0;        double e = -1.0;        double f = 1.5;          System.out.println(Math.acos(c));        System.out.println(Math.acos(d));        System.out.println(Math.acos(e));          // value of f does not lie in between -1 and 1        // so output is NaN        System.out.println(Math.acos(f));    }}
Output:
NaN
1.5159376794536454
0.0
1.5707963267948966
3.141592653589793
NaN

Java-lang package
java-math
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.