I want to label each element in the list in which they appear, so input file as argument #!/usr/bin/python import sys fi

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

I want to label each element in the list in which they appear, so input file as argument #!/usr/bin/python import sys fi

Post by answerhappygod »

I want to label each element in the list in which they appear,so input file as argument
#!/usr/bin/python
import sys
filename=sys.argv[1]
with open(filename) as f:
#what the text file should look like:
a
b
b
b
b
b
c
c
c
c
c
d
d
d
d
d
#what I want the output to look like:
1 a
2 b
5 b
6 b
7 b
8 b
3 c
9 c
10 c
11 c
12 c
4 d
13 d
14 d
15 d
16 d
through the text file start with the first occurrence of eachletter then once those are labeled continue and label the rest inorder
not sure what the best way to go about it is
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply