-1

code :

import re
import json
#open("sbins.txt","r")  
data = open("sbiiins.txt","r")
contents = data.read().strip()



for i, p in enumerate(re.findall(r'"password":[^"]*"(.*?)"', contents):

        print('{}="{}"'.format(i, p))

this code prints outputs this below strings by parsing a text file :

1="pass1425-*"
2="pass1234- "
3="pass0*++"
4="pass*-+"

i need to use these print statements and use them in loop

for example :

ids = (1,2,3,5,6,7,8)

for ind in ids:
     a= ids
      ....
       ....

In above code

1 should return pass1425-*

2 should return pass1234-
...

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40

1 Answers1

0

As the comment said, use a dictionary.

https://www.w3schools.com/python/python_dictionaries.asp

thisdict =  {
  "brand": "Ford",
  "model": "Mustang",
  "year": 1964
}
thisdict["year"] = 2018

Your case:

thisdict =  {
    "1":"pass1425-*",
    "2":"pass1234- ",
    "3":"pass0*++",
    "4":"pass*-+"
}
print(thisdict["2"])

>>>>pass1234-
Jkind9
  • 742
  • 7
  • 24
  • can i make and print the dict itself ? –  Jun 18 '19 at 10:03
  • Yes of course. Ill edit to show you code for your case – Jkind9 Jun 18 '19 at 10:05
  • https://stackoverflow.com/questions/30280856/populating-a-dictionary-using-for-loops-python – Jkind9 Jun 18 '19 at 10:12
  • Youll have to be more specific, i dont know what youre asking in that case. – Jkind9 Jun 18 '19 at 10:38
  • `for i, p in enumerate(re.findall(r'"password":[^"]*"(.*?)"', contents): print('{}="{}"'.format(i, p))` this prints the following `1="pass1425-*" 2="pass1234- " 3="pass0*++" 4="pass*-+"` . How to store the printed values and use them in loop. in this case i have huge values so cant add them manually to the dict. –  Jun 18 '19 at 10:44
  • Create a list then use list.append[] – Jkind9 Jun 18 '19 at 10:48