dictionary and accessing data - dee

A forum for general discussion of the Python programming language.

dictionary and accessing data - dee

Postby dee99 » Fri Sep 16, 2016 2:24 pm

Code: Select all
# file to recreate secret information using a dictionary and a file with a number of position occurrences in sequence - trainee python
listofsentences = []
myfile = open("testdata2.txt")

for eachline in myfile:
    listofsentences.append(eachline.strip())
myfile.close()

listofwords = []
listofpositions = []
# creates an empty dicitionary
dict = {}

for x in range(len(listofsentences)):
   
    
    sentence 
= listofsentences[x]
    

for x in range
(len(sentence)):
    if sentence[x] in listofwords:
         position = listofwords.index(sentence[x])+1
           
         listofpositions
.append(position)
            
    else
:
         listofwords.append(sentence[x])
         position = listofwords.index(sentence[x])+1

         dict
[position] = sentence[x]
         listofpositions.append(position)
#         print(position, listofwords)

#dict = {listofwords}
listofpositions = (listofpositions)
listofwords = (listofwords)
#print(listofwords)
print(listofpositions)
#for i in (listofwords):
  #    print(listofwords[i])
#print(dict)
for k, v in dict.items():
   print(k, v)

k, v = dict.keys(), dict.values()

#print(dict.values())
 

   

#print(listofpositions)
#print (dict.keys())
# help i have two files one with occurences of positions, the other a dictionary with a lookup key and its respective value
for x in range(len(listofpositions)):
    if listofpositions[x] in dict.keys():
                       
                        print
(v)
    else:
        print('hello')
#this above part does not select only one key but all of them and i just want to select one value at a time and recreate the secret info
#print(listofpositions)  
Last edited by micseydel on Fri Sep 16, 2016 2:28 pm, edited 1 time in total.
Reason: Code tags. Initial post lock.
dee99
 
Posts: 2
Joined: Fri Sep 16, 2016 2:04 pm

Re: dictionary and accessing data - dee

Postby buran » Fri Sep 16, 2016 2:32 pm

What is your problem/question?
We are moving to http://www.python-forum.io as of 1 October. Did you register there?
buran
 
Posts: 372
Joined: Tue Apr 08, 2014 4:53 pm
Location: Bulgaria, EU

Re: dictionary and accessing data - dee

Postby dee99 » Fri Sep 16, 2016 2:53 pm

buran wrote:What is your problem/question?

i am trying to access from list of positions file the respective value in the dictionary file
positions file has a list of sequeneces from original sentences number example 1,2,3,4,5,1,6,3,7,8,3,?
dictionary file unique occurences of character for instance
1 = "m"
2 = "y"
3= " " (space)
4=" n"
5= " a"
6= "e"
7= "i"
8= "s"
9= "?"
Spelling should be - my name is ?
regards
d
dee99
 
Posts: 2
Joined: Fri Sep 16, 2016 2:04 pm


Return to General Discussions

Who is online

Users browsing this forum: Bing [Bot] and 5 guests