4 Data Structures one must know in Python

In Python we have 4 built-in data structures which covers 80% of the real-world data structures. These are classified as non-primitive data structures because they store a collection of values in various format than a single value. Some can store data structures within data structures, creating depth and complexity.

Built-in data structures are predefined data structures that come along with Python. Lists and tuples are ordered sequence of objects. Unlike strings that contain only characters, lists and tuples can contain any type of objects.

  • List and tuples are like arrays.
  • Tuples like strings are immutables.
  • Lists are mutables so they can be converted after their creation.
  • Sets are mutable unordered sequence of unique elements whereas frozensets are immutable sets

Lists are enclosed in brackets: l =[1,2,’a’]

Tuples are enclosed in parentheses: t=(1,2,’a’)

Dictionaries are built with curly brackets: d= {‘a’:1, ‘b’:2}

Set are built with curly brackets: s= {1,2,3}

Tuples are faster and consume less memory.

Lists:

            They are used to store data of different data types in a sequential manner. It stores heterogeneous data in sequential order. There are two types of indexing: positive index(most common method) and negative index.

Indexing:

Positive Index means every element has an index that starts from 0 and goes until last element.

Negative Index starts from -1 and it starts retrieving from last element.

Slicing:

In Python List slicing is the most common practice to solve problems efficiently. If we want to use a range of elements from the list we can access those range with slicing and the operator used is colon (:)

Syntax:

List [start:end:index jump]

Type error occurs when data types other than integer are used to access like in our example float is used. Index error occurs when we try to access indexes out of range.

List Functions:

Let us see some functions in the sample code snippet:

Tuple:

            Tuples are same as list but the only exception is that data cannot be changed once entered into the tuple. They are immutable. Since it is immutable the length is fixed, to grow or shrink a tuple we need to create a new tuple. Like list tuple also has some methods

Dictionaries:           

Dictionary is a datastructure which stores the data in the form of key:value pairs. Dictionary is a collection of ordered, changeable and does not allow duplication. Key-value is provided in dictionary to make it more optimized. For better understanding, dictionary can be compared to a telephone directory with tens of thousands of names and phone numbers. Here the constant values are names and phone numbers these are the keys and the various names and phone numbers fed to the keys are called values.

Sets:

            Sets are a collection of unordered elements that are unique. Even if the data is repeated more than once it will be entered in the set only once. It is same as arithmetic sets.

Sets are created same way as in dictionary by using curly brackets but instead of key value pairs we pass values directly.

Now let us see a sample code snippet with set creation and its operations such as union, intersection, difference, symmetric_difference

  • Union combines both sets
  • Intersection finds the elements present in both sets
  • Difference deletes the elements present in both sets and outputs the elements present only in the set
  • Symmetric_difference is same as difference but outputs the data which is remaining in both sets.

These are all the four basic data structures one need to know while learning python programming.

Delete, Truncate and Drop Table in SQL

Let us understand the difference between delete truncate and drop table:

Delete Truncate and Drop Table:

CharacteristicsDeleteTruncateDrop
Command TypeDML(Data Manipulation Language)DDL(Data Definition Language)DDL(Data Definition Language)
Rollback transactionCan be rolled backCannot be rolled backCannot be rolled back
Permanent deleteSince it is DML does not remove records permanentlySince it is DDL removes the records permanentlySince it is DDL removes the records permanently
TriggerTrigger is firedNo trigger usedNo trigger used
PerformanceSlower than truncateFaster than deleteQuick but some complications
Can we use WHERE clause?Yes WHERE clause can be usedNo WHERE clause can be usedNo WHERE clause can be used
SyntaxDELETE FROM table_name;TRUNCATE table_name;DROP table_name;
UsageUsed to delete records in the tableUsed to delete data and keep the table schema as it isUsed to delete data as well as table structure.
Example:Delete from Employee where salary>25000;Truncate table Employee;Drop table Employee;

With the above mentioned tabular form difference we can easily understand the difference between delete, truncate and drop in SQL

Stop saying the phrase „meiner Meinung nach“ / Alternativen zu „meiner Meinung nach“

As you start learning German and preparing for language test, we would have all come across this phrase “meiner Meinung nach” which means  ‘in my opinion’ in English. In each level of German test for example B1, B2 or C1 levels there will be speaking section and in that discussion teil we will always have to say our opinion. It will be redundant to use the same phrase “meiner Meinung nach” instead of that we can use the following phrases and it will also create a good impression to the examiner that we know more phrases.

  • Aus meiner Sicht…     

From my point of view …

  • Wenn du mich fragst: …

        If you ask me …

  • In meinen Augen …

In my eyes …

  • Meiner bescheidenen Meinung nach …

In my humble opinion …

  • Soweit ich das beurteilen kann, …

           As far as I can tell, …

  • So wie ich das sehe, …

           The way I see it …

  • Meiner Auffassung nach …

In my notion…

  • Meines Erachtens …

In my opinion …

In telc or Goethe B1, B2 or higher levels in Sprechen Teil we will have to speak about our opinion in discussion or presentation. In these we can use the above mentioned phrases instead of “meiner Meinung nach”

How to create an OData Service in SAP

  1. The OData service is developed on a new project in the SAP system. Therefore start with the Transaction SEGW.
  2. Click New in the toolbar.
  3. Please enter a new project name and a short description on the popup fenster. Define also a package and finally confirm the entries through tick mark.
  4. A new project is now created. There are four folders under the new project. Right click on the folder ‘DATA MODEL’ and choose import from DDIC structure. The already available ABAP Dictionary structure can be imported directly and it is not necessary to manually assign an OData-service to each field. In addition to the ABAP structures, you can also import Type definitions from BAPI-Function module parameters or search help.
  5. In the popup fenster, provide the entity type and also provide the structure SFLIGHT in the respective fields. Ensure that the option Create default entity set is selected. Finally click the ‘Next’.
  6. In the next window, you will see all the fields of the table SFLIGHT. Now click all the fields of the structure, except the field MANDT. Click ‘Next’.
  7. In the next window, you will see all the fields with their respective Datatype. The primary keys of this structure must be confirmed through the checkbox column ‘IS KEY’. So please select the checkbox for the respective primary key fields of the structure. In this case, let us choose the CARRID, CONNID, FLDATE as our primary keys. Once you are done with the selection, please confirm the entries by selecting the ‘FINISH’ Button.
  8. As you can see, the Data model consists of the Entity types and Entity sets. The Entity Type Flights contains the properties folder. The properties folder contains all the fields of the structure. It displays the Edm core type and Label which describes the fields. The entityset ‘Flightsset’ is created as we checked this option ‘Create Default Entity Set’.
  9. The CRUDQ Methods of the Entityset is available in the folder service implementation.

What are the different query option in ODATA-URL

The OData URL can be modified to represent the corresponding results. It provides various Filter options

$Filter: It is like the WHERE condition. The below URL in the browser returns the products with the price less than 100.

https://services.OData.org/v3/OData/OData.svc/Products?$filter=Price lt 100    

$Select: It is used to display only the respective columns of the table.

https://services.OData.org/v3/OData/OData.svc/Products?$select=ID,Categories

In the above example, it displays only the columns ID and Category.

$Orderby: It is used to sort the results. The below url displays the products with the price in decreasing order.

https://services.OData.org/v3/OData/OData.svc/Products?$orderby=Price desc    

$top :  It displays the initial records of the table.

https://services.OData.org/v3/OData/OData.svc/Products?$top=3

$skip: The Data records can be skipped through this option.

https://services.OData.org/v3/OData/OData.svc/Products?$skip=4

$expand: It is used to join two tables and display corresponding results.

https://services.OData.org/v3/OData/OData.svc/Categories(1)?$expand=Products

Multiple query options is possible through the & symbol

InitialURL/Entityset?$option1=……&$option2=….&$optionN

How to construct an OData service in SAP ABAP

ODATA SERVICE CONSTRUCTION

Entity container: It contains all the entity sets.

Entity set: It represents a table. It is based on the entity type.

Entity type: All the fields(properties) and the primary keys are mentioned.

Property: It represents the fields along with data type.

Entity: It describes a line of record in the data table.

Association: It connects the primary and foreign key fields. It represents the cardinality of the relationship (1:1, 1: n).

Navigation: The two different entity sets can be related and represented through the navigation.

What is an OData service document

OData service document represents a service which includes entity sets, uniform resource identifier (URI)

It can be opened through the browser with the URI / URL

For example, let us consider the following OData service.

http://services.odata.org/v3/OData/OData.svc/

If you open this URL in browser, it shows up the different entity sets.

Entitysets shown in Browser

As you can see in the above image, the entitysets in this OData service are Products, Productdetails, Categories, Suppliers, Persons, PersonDetails, Advertisements. So it includes totally seven entitysets. The entityset ‘Category’ includes information about all categories.

If the categories is added to the above URL like

http://services.odata.org/v3/OData/OData.svc/Categories

The above url in the browser would list down all the categories.

Similarly if you wish to see all the Products. Then follow this link

http://services.odata.org/v3/OData/OData.svc/Products

URL is case sensitive. So the first letter ‘P’ in Products must be written in Capital. Otherwise it does not work.

It is much similar to the Transaction SE11 (ABAP Dictionary) where we give the Table name. The Data contents can be displayed for this table.

The URLs mentioned above executes the HTTP-Get methods, which in turn calls the Read-OData method. In the background, the data would be retrieved and the result is sent back.

Let us look into an example of retrieving data records with single primary key.

Specific line of record can also be retrieved by specifying the primary key value in the URL.

http://services.odata.org/v3/OData/OData.svc/Products(5)

In the above URL, the products with the ID 5 will be retrieved.

Retrieving data records with two primary keys.

/Entityset( p_key1 = ‘Value1’, p_key2 = ‘Value2’ )

In the above case, both the primary key fields are of datatype string. So the value is mentioned in quotes. If the datatype is integer, then quotes should not be used.

Retrieving data records with WHERE clause.

All the products with a particular category ID can also be retrieved. To achieve this, it must be predefined in the services. We can also navigate from one entity set to another. For example, in the below URL, only the data from the product entity set are displayed.

https://services.OData.org/v3/OData/OData.svc/Categories(5)/Products

Retrieving data records from two different entity sets

This option is much like the JOIN query in SQL. The data from two different entity sets are displayed with a WHERE condition.

https://services.OData.org/v3/OData/OData.svc/Categories(2)?$expand=Products

How does OData service works

OData services works through entity sets and entities. Data is represented in the form of Tables.

Tables are referred as Entity sets and the lines of record are referred as entities.

The Data is accessed through the following OData methods. These OData methods are referred as CRUD methods.

OData MethodHttp MethodDescription and its relation to sql command
CreatePOSTIt creates a new record. It is similar to INSERT command in SQL
ReadGETIt reads the records. It is similar to SELECT command in SQL.
The Read method from OData can be further classified.
For example, the Read method is used to read only one record.
The Query method is used to read more lines of record.
UpdateUPDATEIt updates the records. It is similar to UPDATE command in SQL
DeleteDELETEIt deletes the records. It is similar to DELETE command in SQL

What is OData service in SAP

  • It is a http type protocol
  • The protocol is between the other applications (Web browser etc) and SAP system.
  • The OData-open data protocol supports two formats Atom and JSON. It can also be controlled in different ways through URLs.
  • It follows the REST Architecture (Client/Server).
  • The Data from the source side and the server side is identified through the uniform resource identifier.
  • OData service is a logical data model. The Data is stored as entities.
  • The OData service is identified through URL/URI.