Python Forum
making a dictionary from a list, one key with multiple values in a list within a list
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
making a dictionary from a list, one key with multiple values in a list within a list
#1
i have an assignment: and basically here it is and i get stuck on this.
write = W,
read = R,
execute= X.

The first line contains the number N — the number of files contained in the filesystem. The following N lines contain the file names and allowed operations with them, separated by spaces. The next line contains an integer M — the number of operations to the files. In the last M lines specify the operations that are requested for files. One file can be requested many times.

You need to recover the control over the access rights to the files. For each request your program should return OK if the requested operation is valid or Access denied if the operation is invalid.

the input is:
4
helloworld.exe R X
pinglog W R
nya R
goodluck X W R

5
read nya
write helloworld.exe
execute nya
read pinglog
write pinglog

the output:
OK
Access denied
Access denied
OK
OK

i am having trouble with making a dictionary. Just making a dictionary, the rest I think i can figure that out.
here is my code so far:
N = int(input())
lst =[]
W = "write"
R = "read"
X = "execute"
for lines in range(N):
    lines = str(input()).split()
    
print(lst)
this is not much. but it prints [['Helloworld', 'W', 'R'], ['pinglog', 'W'], ['data', 'X', 'W', 'R']]
and now i get stuck on how am i going to make it a dictionary. sorry for my last posts with no BB code...
Reply


Messages In This Thread
making a dictionary from a list, one key with multiple values in a list within a list - by rhai - Oct-20-2018, 03:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  A function that checks if the list is sorted pooyan89 16 16,886 Apr-22-2024, 09:14 AM
Last Post: DeaD_EyE
Sad IMC Calculator but with a list of patients Booba 1 1,004 Jun-11-2023, 07:21 AM
Last Post: deanhystad
  List joining deatz 14 3,280 Dec-21-2022, 03:34 AM
Last Post: deatz
  Help with list homework eyal123 5 1,702 Nov-18-2022, 03:46 PM
Last Post: deanhystad
  How to sort a list with duplicates and return their unique indices. Echoroom 3 3,560 Sep-23-2022, 07:53 AM
Last Post: deanhystad
  help with adding duplicates elements together in a list 2ECC3O 5 2,092 Sep-10-2022, 07:11 AM
Last Post: 2ECC3O
  how to reverse a list and store in another list in python SuperNinja3I3 6 3,336 Aug-14-2022, 06:36 PM
Last Post: DeaD_EyE
  list digit into number Voldyy 2 1,565 Jul-10-2022, 06:13 PM
Last Post: deanhystad
  How to remove extra space from output list? longmen 3 1,828 May-05-2022, 11:04 PM
Last Post: longmen
  How to fix list index out of range longmen 26 6,132 Apr-27-2022, 05:46 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020