Skip to content

Conversation

gbertoncelli
Copy link

@gbertoncelli gbertoncelli commented May 24, 2018

Changed an exercise that seemed to be with a wrong solution.

numbers = [x for x in values.split(",") if int(x)%2!=0]
values = raw_input() # input() in python3
numbers = [int(x)**2 if int(x) % 2 != 0 else int(x) for x in values.split(",")]
print ",".join(numbers)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great solution but here numbers list contains integers whereas join() method is only applicable with iterables that contain either strings or unicode object. You need to convert values in numbers to string first to be able to use join().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants