You are not logged in. Please login at www.codechef.com to post your questions!

×

I ma getting RunTime error in CleanUP problem

Here is my Code Please help!

asked 02 Oct '17, 03:54

pratik_nalage's gravatar image

2★pratik_nalage
11
accept rate: 0%

edited 02 Oct '17, 03:55


T=int(input()) for i in range(T): #cj=[] n,m=map(int,input().split(' ')) cj=list(map(int,input().split(' '))) #cj.extend(ele) fele=[j for j in range(1,n+1)] ex = [x for x in fele if x not in cj] chef=[e for c,e in enumerate(ex) if c%2==0] other=[e for d,e in enumerate(ex) if d%2==1] for l in chef[:]: print(l,end=' ') print() if not other: print() else: for m in other: print(m,end=' ')

Runs fine in repl.it and terminal. No clue why this might be happening? Little help can push me alot ahead. Thanks

link

answered 26 Aug '18, 00:55

bgulati1994's gravatar image

0★bgulati1994
101
accept rate: 0%

@bgulati1994 Couple of things from your code above...

Why don't you just print the "other" the same way as the "chef"? You seem to miss an endline on other when there are jobs to do, unless you snipped that by accident.

Also note for full slice usage that chef's jobs are ex[::2] and other's jobs are ex[1::2] - the final "2" being the step. Slicing will return an empty list if appropriate.

Another neat feature you can use here is unpacking; prefacing an iterable with an asterisk in a function call presents the contained items as a list of parameters, so print(*ex[::2]) should print the jobs of interest for chef.

link

answered 26 Aug '18, 08:16

joffan's gravatar image

5★joffan
9488
accept rate: 13%

edited 26 Aug '18, 08:44

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×545
×528
×434
×280
×29

question asked: 02 Oct '17, 03:54

question was seen: 317 times

last updated: 26 Aug '18, 08:44