Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taskB_inlab
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cs251_group35
taskB_inlab
Commits
9a3c24e1
Commit
9a3c24e1
authored
Aug 24, 2016
by
DIVYANSH
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
150020086
parents
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
0 deletions
+50
-0
task1.py
task1.py
+11
-0
task2.py
task2.py
+9
-0
task3.py
task3.py
+24
-0
transpose.txt
transpose.txt
+6
-0
No files found.
task1.py
0 → 100644
View file @
9a3c24e1
def
function1
(
string1
,
string2
,
listVariable
):
tup1
=
tuple
(
string1
);
#making tuple of characters in string 1
tup2
=
tuple
(
string2
);
#making tuple of characters in string 2
tup3
=
list
(
zip
(
tup1
,
tup2
));
#zipping the two tuples in a list
return
listVariable
+
tup3
#returning the appended list
string1
=
'CS251'
;
string2
=
'python'
;
ini_list
=
[
1
,
2
,
3
,
4
,
5
];
print
(
ini_list
);
#print initial list
print
(
function1
(
string1
,
string2
,
ini_list
));
#print updated list
\ No newline at end of file
task2.py
0 → 100644
View file @
9a3c24e1
def
function2
(
listVariable
,
n
):
def
get_ele
(
n
):
#function returning lambda function in x(a tuple), n is element number
return
lambda
x
:
x
[
n
]
g
=
get_ele
(
n
);
#returning a function in x to g, g will return nth element of required tuple
lis
=
list
(
map
(
g
,
listVariable
));
#map is used to apply function g to each element of listVariable
stuple
=
sorted
(
listVariable
,
key
=
g
);
#sorting the tuple listVariable w.r.t value of function g
print
(
lis
);
return
stuple
;
\ No newline at end of file
task3.py
0 → 100644
View file @
9a3c24e1
fil
=
open
(
'matrix.txt'
,
'r'
);
#opening matrix.txt in fil variable
a
=
fil
.
read
();
#taking text in a string
arr
=
a
.
split
();
#splitting string in words
m
=
int
(
arr
[
0
]);
#returning number of rows in m and columns in n
n
=
int
(
arr
[
1
]);
Arr
=
[[
0
for
j
in
range
(
n
)]
for
i
in
range
(
m
)];
#applying for loop to create the matrix in Arr
for
i
in
range
(
m
):
#reading matrix Arr
for
j
in
range
(
n
):
Arr
[
i
][
j
]
=
arr
[
2
+
(
n
*
i
)
+
j
];
Trans
=
[[
0
for
j
in
range
(
m
)]
for
i
in
range
(
n
)];
#applying for loop to create the matrix in Trans
for
i
in
range
(
n
):
for
j
in
range
(
m
):
Trans
[
i
][
j
]
=
Arr
[
j
][
i
];
fil
.
close
();
#closing input file
fil2
=
open
(
'transpose.txt'
,
'w'
);
#loading file to be written
st
=
str
(
n
)
+
" "
+
str
(
m
)
+
'
\n
'
;
#writing number of rows and columns
fil2
.
write
(
st
);
for
i
in
range
(
n
):
for
j
in
range
(
m
):
fil2
.
write
(
str
(
Trans
[
i
][
j
]));
#writing each row of transpose matrix
fil2
.
write
(
' '
);
fil2
.
write
(
'
\n
'
);
fil2
.
close
();
#closing final file
\ No newline at end of file
transpose.txt
0 → 100644
View file @
9a3c24e1
5 5
1 6 11 16 21
2 7 12 17 22
3 8 13 18 23
4 9 14 19 24
5 10 15 20 25
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment