Wednesday, February 28, 2024

Combine related information using zip function

Example 1:

 # Example with three lists

names = ["Alice", "Bob", "Charlie"]
ages = [25, 30, 22]
cities = ["New York", "San Francisco", "Los Angeles"]

# Using zip to combine the three lists
combined = zip(names, ages, cities)

# Converting the result to a list for printing
# Example with three lists
names = ["Alice", "Bob", "Charlie"]
ages = [25, 30, 22]
cities = ["New York", "San Francisco", "Los Angeles"]

# Using zip to combine the three lists
combined = zip(names, ages, cities)

# Converting the result to a list for printing
result_list = list(combined)

# Output
print(result_list)
Output:
[('Alice', 25, 'New York'), ('Bob', 30, 'San Francisco'), 
('Charlie', 22, 'Los Angeles')]

Modified Example 1:

# Example with three lists
names = ["Alice", "Bob", "Charlie"]
ages = [25, 30, 22]
cities = ["New York", "San Francisco", "Los Angeles"]

# Using zip to combine the three lists
combined = zip(names, ages, cities)

# Converting the result to a list for printing
# Example with three lists
names = ["Alice", "Bob", "Charlie"]
ages = [25, 30, 22]
cities = ["New York", "San Francisco", "Los Angeles"]

# Using zip to combine the three lists
combined = zip(names, ages, cities)

for emp in combined:
print(f"Employee name: {emp[0]},
Employee Age: {emp[1]} and Work location is {emp[2]}")

Output:
Employee name: Alice, Employee Age: 25 and Work location is New York
Employee name: Bob, Employee Age: 30 and Work location is San Francisco
Employee name: Charlie, Employee Age: 22 and Work location is Los Angeles

**kwargs to handle any number of keyword arguments

 def my_grocery_list(**kwargs):

    print(kwargs)
print(type(kwargs))
for item in kwargs:
print(f"{kwargs[item]} {item}")

my_grocery_list(toothpaste='Colgate',toothbrush='Colgate',
num_of_toothbrush=2)

Output:

{'toothpaste': 'Colgate', 'toothbrush': 'Colgate',
'num_of_toothbrush': 2}
<class 'dict'> Colgate toothpaste Colgate toothbrush 2 num_of_toothbrush

*args to accept any number of positional arguments

 Consider the below case:

We need to all the sum all the inputs. Number of inputs are unknown.

sum(5,8,9)
The above will not work. sum() takes at most 2 arguments (3 given).

But, sum() can calculate the sum of Iterable i.e. means List, Tuple etc.

sum([5,8,9])
or
sum((5,8,9))
* means any number of arguments.
def sum_of_nums(*args):
print(args) -> o/p: (3, 8, 8, 190)
print(type(args)) -> <class 'tuple'>
return sum(args)


print(sum_of_nums(3, 8, 8, 190))

How to access Nested function from outside?

def func_a():
print('Task triggered for function A')

def func_b():
print('Task triggered for function B')

In this case, we cannot call func__b from outside. We can only access 
func_b() from inside of func_a().

def func_a():
print('Task triggered for function A')

def func_b():
print('Task triggered for function B')

func_b()
func_a()

To overcome this, we can return func_b as shown below:
def func_a():
print('Task triggered for function A')

def func_b():
print('Task triggered for function B')

# Notice, I am only providing the function name
return func_b


task_b = func_a()
task_b()

Wednesday, May 24, 2023

How to do filtering in XSLT

Filtering is a common requirement in most of the integration scenarios. Also, the condition for that can be dynamically changed based on the business requirement.



The above video explains -

  • How can we use parameters in XSLT
  • How to use tokenize function in XSLT

For complete XSLT demo video series, check out:

https://www.youtube.com/@btpintegration






Tuesday, May 23, 2023

XSLT Mapping in Cloud Integration - Video Series

XSL is a very powerful styling language. This is commonly used to do transformations from XML to XML or XML to HTML in SAP cloud integration.

Currently SAP Cloud Integration supports XSLT 3.0 capabilities.

The following video shows how to do grouping in XSLT.




Used XSLT element:  xsl:for-each-group

In this video, you will get to know:

1. How easily we can use VS extension to write XSLT
2. How we can use the same XSL file for XSLT mapping in Cloud Integration (CPI)

For complete XSLT demo series, check out:

https://www.youtube.com/@btpintegration/playlists