Can post a code but afraid of plagiarism

I

indar kumar

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public

Thank You

I have found this forum very helping...GOD BLESS YOU ALL
 
I

indar kumar

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly,suggest how can I post it for review here without masking it visible for public

hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}


Hi,
I want to print a value before a particular value inside of a list associated with a key inside main dictionary(hosts) not the one inside nested dictionary.

Forexample,
I want the user to input ip e.g. 192.168.0.2 and then search through dictionary print MAC e.g.02:02:02:02:02:02 that is just before that IP. Note thathost id(e.g.PC2) is not known user just inputs IP.
 
E

Emile van Sebille

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public

hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],'PC1':['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}


Hi,
I want to print a value before a particular value inside of a list associated with a key inside main dictionary(hosts) not the one inside nested dictionary.

Forexample,
I want the user to input ip e.g. 192.168.0.2 and then search through dictionary print MAC e.g.02:02:02:02:02:02 that is just before that IP. Note that host id(e.g.PC2) is not known user just inputs IP.

Like this?:
hosts={'PC2':['02:02:02:02:02:02', '192.168.0.2', '200',
.... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}],
.... 'PC1':['01:01:01:01:01:01', '192.168.0.1', '200',
.... {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531),
.... '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}
searchfor = '192.168.0.1'

print [ ii[0] for ii in hosts.values() if ii[1] == searchfor ]
['01:01:01:01:01:01']
 
I

indar kumar

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public

Just the value e.g.01:01:01:01:01:01 not the list
 
I

indar kumar

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible for public

Can I do the following to just get the value as string not the type list?

searchfor = '192.168.0.2'
z=[ii[0] for ii in hosts.values() if ii[1] == searchfor]
 
D

Dennis Lee Bieber

I have following nested dictionary

hosts={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531)}], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200', {'192.168.0.2': ('02:02:02:02:02:02', 1390461798.531), '192.168.0.1': ('01:01:01:01:01:01', 1390461787.78)}]}


How can I print a particular tuple from this table?


What I am trying to do is
input1=raw_input("Please enter id of host and IP that you want to be resolved")
z=input1.split()
print("PC3 resolved"+' '+z[1]+' to'+hosts[z[0]][3] z[1])

This would be a lot easier for you to figure out if you do it in steps:

First extract all the data for the user provided host (and use tuple
assignment to give useful names to the input fields).

host, ip = raw_input("...").split()
aHost = hosts[host]
cache = aHost[3]
ipMap = cache[ip]
MAC = ipMap[0]

(If you really want the all-in-one: MAC = hosts[host][3][ip][0] )

Note that there is no error checking in that -- if the input has a typo
and doesn't find an entry the program will die with an exception.
 
I

indar kumar

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly,suggest how can I post it for review here without masking it visible for public

Thanks

config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200']}

What if I want to search for a particular value inside the lists of all keys except one that user inputs and also want to print that value.

Forexample, user gets prompt to enter following four parameters
prompt1= "Enter <host_id> <ip addr> "

After user has input I have added this information into above dictionary(config_database) but I also need to check if this ip is not already assigned to a PC other than the one which user inputs. So how to search for particular value inside the lists associated with keys other than inside that one which user inputs(because obviously then it would match so just want to skipits own entry) and print that value.
 
R

Rustom Mody

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly, suggest how can I post it for review here without masking it visible forpublic



Thanks



config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200']}



What if I want to search for a particular value inside the lists of all keys except one that user inputs and also want to print that value.



Forexample, user gets prompt to enter following four parameters

prompt1= "Enter <host_id> <ip addr> "



After user has input I have added this information into above dictionary(config_database) but I also need to check if this ip is not already assigned to a PC other than the one which user inputs. So how to search for particular value inside the lists associated with keys other than inside that onewhich user inputs(because obviously then it would match so just want to skip its own entry) and print that value.


Does this suggest some ideas to you??
config_database={'PC2': ['02:02:02:02:02:02', '192.168.0.2', '200'], 'PC3': ['03:03:03:03:03:03', '192.168.0.3', '200'], 'PC1': ['01:01:01:01:01:01', '192.168.0.1', '200']}
{pc:config_database[pc][1] for pc in config_database.keys()}
{'PC2': '192.168.0.2', 'PC3': '192.168.0.3', 'PC1': '192.168.0.1'}

Or even simpler
{pc:config_database[pc][1] for pc in config_database}
{'PC2': '192.168.0.2', 'PC3': '192.168.0.3', 'PC1': '192.168.0.1'}
 
I

indar kumar

Hi,



I want to show a code for review but afraid of plagiarism issues. Kindly,suggest how can I post it for review here without masking it visible for public

Yes now I want to search for an ip that user has input but skipping the keywhich user has input. e.g. user entered PC1 and 192.168.0.1. Now I want toscan through config_database to see if this ip is already in it. But PC1 192.168.0.1 is added to config_database before searching so I want to skip PC1 key during searching so that I can see if this Ip is not already associated with any other host.
 
S

Steven D'Aprano

What if I want to search for a particular value inside the lists of all
keys except one that user inputs and also want to print that value.

Then go right ahead and do so. You are learning Python, so this should be
covered in your course. Did you follow the advice to work through the
Python tutorial?

http://docs.python.org/2/tutorial/
http://docs.python.org/3/tutorial/

depending on whether you are using Python 2 or 3.

This is supposed to be your work, not ours. Start by writing down how you
would solve this problem as a human being:

for each key:
if the key is the one the user inputted, skip this key
otherwise:
get all the lists for this key
for each list:
search for the value


Now change that to Python code. Don't just ask us to solve the problem
for you.
 
D

Dennis Lee Bieber

You can stop repeating that caveat for one thing, and provide some
context of what/who you are replying to.
Yes now I want to search for an ip that user has input but skipping the key which user has input. e.g. user entered PC1 and 192.168.0.1. Now I want to scan through config_database to see if this ip is already in it. But PC1 192.168.0.1 is added to config_database before searching so I want to skip PC1 key during searching so that I can see if this Ip is not already associated with any other host.

And what is stopping you? You don't know how to process all the entries
in the main dictionary, or you don't know how to skip an entry when you
find it?

-=-=-=-=- (more non-Python)

/* Aba-guernqrq rzhyngvba bs Argjbex NEC genssvp */

argjbex. = ""
argjbex.0 = 0 /* ahzore bs qrsvarq ubfgf */
qb sberire
fnl " "
fnl " "
fnl "Ragre pbasvthengvba punatr va gur sbez:"
fnl " ubfganzr ZNP VC gvzrbhg"
cnefr chyy ubfganzr ubfgZNP ubfgVC ubfgGvzrbhg

vs ubfganzr = "" gura
qb
qb u = 1 gb argjbex.0
fnl "Ubfg " argjbex.u.ubfg argjbex.u.znp argjbex.u.vc
argjbex.u.gvzrbhg
fnl "Pnpur"
qb n = 1 gb argjbex.u.pnpur.0
fnl " " argjbex.u.pnpur.n.znp argjbex.u.pnpur.n.vc
raq
fnl " "
raq
rkvg
raq

pnyy NECCebor ubfganzr ubfgZNP ubfgVC

vs inyvq gura
qb
pnyy hcqngr ubfganzr ubfgZNP ubfgVC ubfgGvzrbhg
pnyy NECNaabhapr ubfganzr ubfgZNP ubfgVC
raq
ryfr
qb
pnyy erzbir ubfganzr
raq
raq

NECCebor: cebprqher rkcbfr argjbex. inyvq
cnefr net ua uz uv
fnl " "
fnl "NEC Cebor: " uz " ss:ss:ss:ss:ss:ss 0.0.0.0 " uv
qb u = 1 gb argjbex.0
vs argjbex.u.ubfg <> ua gura
vs argjbex.u.vc = uv gura
qb
inyvq = 0
erghea
raq
raq
inyvq = 1
erghea

hcqngr: cebprqher rkcbfr argjbex.
cnefr net ua uz uv ug
qb u = 1 gb argjbex.0
vs argjbex.u.ubfg = ua gura
qb
fnl "Ubfg " ua " hcqngrq"
argjbex.u.znp = uz
argjbex.u.vc = uv
argjbex.u.gvzrbhg = ug
erghea
raq
raq

u = argjbex.0 + 1
fnl "Ubfg " ua " nqqrq gb argjbex"
argjbex.u.ubfg = ua
argjbex.u.znp = uz
argjbex.u.vc = uv
argjbex.u.gvzrbhg = ug
argjbex.u.pnpur. = ""
argjbex.u.pnpur.0 = 0
argjbex.0 = u
erghea

NECNaabhapr: cebprqher rkcbfr argjbex.
cnefr net ua uz uv
fnl " "
fnl "NEC Naabhapr " ua uz " 0:0:0:0:0:0 " uv uv
qb u = 1 gb argjbex.0
vs argjbex.u.ubfg <> ua gura
qb
arj = 1
qb n = 1 gb argjbex.u.pnpur.0
vs argjbex.u.pnpur.n.znp = uz be argjbex.u.pnpur.n.vc = uv
gura
qb
fnl "Ubfg " argjbex.u.ubfg " hcqngrq " uz uv
argjbex.u.pnpur.n.znp = uz
argjbex.u.pnpur.n.vc = uv
arj = 0
raq
raq
vs arj gura
qb
n = argjbex.u.pnpur.0 + 1
fnl "Ubfg " argjbex.u.ubfg " nqqrq " uz uv
argjbex.u.pnpur.n.znp = uz
argjbex.u.pnpur.n.vc = uv
argjbex.u.pnpur.0 = n
raq
raq
raq
erghea

erzbir: cebprqher rkcbfr argjbex.
cnefr net ua
fnl "Ubfg " ua " erzbirq sebz argjbex"
uy = 0
qb u = 1 gb argjbex.0
vs argjbex.u.ubfg = ua gura
uy = u
raq
vs uy <> 0 gura
qb
qb ub = (uy + 1) gb argjbex.0
uq = ub - 1
argjbex.uq. = argjbex.ub.
raq
ur = argjbex.0
argjbex.ur. = ""
argjbex.0 = ur - 1
raq
erghea
-=-=-=-=-

Does not have an independent look-up command but does have to do
look-ups to handle updates and errors.

C:\Users\Wulfraed\Documents>arp.rx


Enter configuration change in the form:
hostname MAC IP timeout
me 2:1:3:4:6:5 192.168.0.1 50

ARP Probe: 2:1:3:4:6:5 ff:ff:ff:ff:ff:ff 0.0.0.0 192.168.0.1
Host me added to network

ARP Announce me 2:1:3:4:6:5 0:0:0:0:0:0 192.168.0.1 192.168.0.1


Enter configuration change in the form:
hostname MAC IP timeout
you 1:2:3:4:5:6 192.168.10.10 50

ARP Probe: 1:2:3:4:5:6 ff:ff:ff:ff:ff:ff 0.0.0.0 192.168.10.10
Host you added to network

ARP Announce you 1:2:3:4:5:6 0:0:0:0:0:0 192.168.10.10 192.168.10.10
Host me added 1:2:3:4:5:6 192.168.10.10


Enter configuration change in the form:
hostname MAC IP timeout
them 6:5:4:3:2:1 10.10.0.10 100

ARP Probe: 6:5:4:3:2:1 ff:ff:ff:ff:ff:ff 0.0.0.0 10.10.0.10
Host them added to network

ARP Announce them 6:5:4:3:2:1 0:0:0:0:0:0 10.10.0.10 10.10.0.10
Host me added 6:5:4:3:2:1 10.10.0.10
Host you added 6:5:4:3:2:1 10.10.0.10


Enter configuration change in the form:
hostname MAC IP timeout
false a:b:c:d:e:f 192.168.0.1 10

ARP Probe: a:b:c:d:e:f ff:ff:ff:ff:ff:ff 0.0.0.0 192.168.0.1
Host false removed from network


Enter configuration change in the form:
hostname MAC IP timeout
me a:b:c:d:e:f 192.168.0.1 10

ARP Probe: a:b:c:d:e:f ff:ff:ff:ff:ff:ff 0.0.0.0 192.168.0.1
Host me updated

ARP Announce me a:b:c:d:e:f 0:0:0:0:0:0 192.168.0.1 192.168.0.1
Host you added a:b:c:d:e:f 192.168.0.1
Host them added a:b:c:d:e:f 192.168.0.1


Enter configuration change in the form:
hostname MAC IP timeout

Host me a:b:c:d:e:f 192.168.0.1 10
Cache
1:2:3:4:5:6 192.168.10.10
6:5:4:3:2:1 10.10.0.10

Host you 1:2:3:4:5:6 192.168.10.10 50
Cache
6:5:4:3:2:1 10.10.0.10
a:b:c:d:e:f 192.168.0.1

Host them 6:5:4:3:2:1 10.10.0.10 100
Cache
a:b:c:d:e:f 192.168.0.1


Press ENTER key to exit...
 
P

Piet van Oostrum

indar kumar said:
Hi,



I want to show a code for review but afraid of plagiarism issues.
Kindly, suggest how can I post it for review here without masking it
visible for public

Can I do the following to just get the value as string not the type list?

searchfor = '192.168.0.2'
z=[ii[0] for ii in hosts.values() if ii[1] == searchfor]

If you want to extract an element of a list use indexing, like mylist[0].

If you don't know these things or can't find this out yourself, you have a serious lack of knowledge about Python, or maybe about programming, and it is time to learn that first.
 
B

bob gailer

I had offered to provide some off-line tutoring. My reaction is exactly
what you are saying - he needs to learn the basics. The code he sent me
(after much asking to see some code) was buggy, and a lot of it were the
various suggestions we all made.

I feel for indar. He is in over his head. I recommend we stop trying to
respond to all his requests.
 
D

Dennis Lee Bieber

And my apologies to the rest of the readers for the quick and dirty
REXX entries... My feeling was that if the OP could figure out the
simplistic obscuration AND was willing to learn a second language giving
functional examples, they deserved the hints.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top