You are not logged in. Please login at 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

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 and terminal. No clue why this might be happening? Little help can push me alot ahead. Thanks


answered 26 Aug '18, 00:55

bgulati1994's gravatar image

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.


answered 26 Aug '18, 08:16

joffan's gravatar image

accept rate: 13%

edited 26 Aug '18, 08:44

toggle preview

Follow this question

By Email:

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



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "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:


question asked: 02 Oct '17, 03:54

question was seen: 317 times

last updated: 26 Aug '18, 08:44