here is the problem I am having. I have a list of strings: ["a","b","b","b","b","b","c","c","c","c","c","d","d","d","d",

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

here is the problem I am having. I have a list of strings: ["a","b","b","b","b","b","c","c","c","c","c","d","d","d","d",

Post by answerhappygod »

here is the problem I am having. I have a list of strings: ["a","b","b","b","b","b","c","c","c","c","c","d","d","d","d","d"]
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
3 c
4 d
5 b
6 b
7 b
8 b
9 c
10 c
11 c
12 c
13 d
14 d
15 d
16 d
through the text file start with the first occurrence of each letter then once those are labeled continue and label the rest in order
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