DEV Community

Guru prasanna
Guru prasanna

Posted on • Edited on

1

Weekend Tasks - List

Task:1
s = "a4k3b2"

1) Write a program to get the output 'abbbbklllbcc'

s = "a4k3b2"
output = ""
i = 0

while i < len(s):
    first = s[i]  
    second =s[i + 1] 
    if second.isdigit():
        alpha=chr(ord(first)+1)
        output=output+ first+ (int(second)*alpha)
        i+=2

print(output)
Enter fullscreen mode Exit fullscreen mode

Output:

abbbbklllbcc

2) Write a program to get the output 'aaaaakkkkbbb'

s = "a4k3b2"
output = ""
i = 0

while i < len(s):
    first = s[i]  
    second =s[i + 1] 
    if second.isdigit():
        output=output+ first+ (int(second)*first)
        i+=2

print(output)
Enter fullscreen mode Exit fullscreen mode

Output:

aaaaakkkkbbb

Task:2

matrix = [[10,20,30], [40,50,60], [70,80,90]]

Join the given matrix into single list using comprehensive for and normal for loop.
Method:1(Using normal for loop)

matrix = [[10,20,30], [40,50,60], [70,80,90]]
output=[]

for i in matrix:
    for j in i:
        output.append(j)
print(output)
Enter fullscreen mode Exit fullscreen mode

Method:2(Using comprehensive for loop)

matrix = [[10, 20, 30], [40, 50, 60], [70, 80, 90]]

output = [j for i in matrix for j in i]
print(output)
Enter fullscreen mode Exit fullscreen mode

Output:

[10, 20, 30, 40, 50, 60, 70, 80, 90]
Enter fullscreen mode Exit fullscreen mode

Task:3
l = ['ABC','DEF', 'GHI', 'JKL']
Get OUTPUT: ['ABC', 'def','GHI', 'jkl']

l = ['ABC', 'DEF', 'GHI', 'JKL']

output = [] 
for i, alpha in enumerate(l):
    if i % 2 != 0:
        output.append(alpha.casefold())
    else:
        output.append(alpha)
print(output)
Enter fullscreen mode Exit fullscreen mode

Output:

['ABC', 'def', 'GHI', 'jkl']
Enter fullscreen mode Exit fullscreen mode

Transpose Matrix: Transpose of a matrix is obtained by changing rows to columns and columns to rows.

Image description
a)

matrix = [[10,20,30], 
          [40,50,60], 
          [70,80,90]]
output=[]

for i in range(len(matrix[0])):
    rows=[]        
    for row in matrix:
        rows.append(row[i])
    output.append(rows)

print(output)
Enter fullscreen mode Exit fullscreen mode

Output:

[[10, 40, 70], [20, 50, 80], [30, 60, 90]]
Enter fullscreen mode Exit fullscreen mode

b) Row wise total (10+20+30) (40+50+60)

matrix = [[10,20,30], 
          [40,50,60], 
          [70,80,90]]

for inner in matrix:
    total = 0
    for num,index in enumerate(inner):
        total+=index
    print(total)
Enter fullscreen mode Exit fullscreen mode

Output:

60
150
240
Enter fullscreen mode Exit fullscreen mode

Billboard image

Monitor more than uptime.

With Checkly, you can use Playwright tests and Javascript to monitor end-to-end scenarios in your NextJS, Astro, Remix, or other application.

Get started now!

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay