[issue41518] incorrect printing behavior with parenthesis symbols

2020-08-11 Thread Ramesh Sahoo


Ramesh Sahoo  added the comment:

Thank Steven for correcting and guiding me.

--

___
Python tracker 
<https://bugs.python.org/issue41518>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41518] incorrect printing behavior with parenthesis symbols

2020-08-11 Thread Ramesh Sahoo


Ramesh Sahoo  added the comment:

Additional note: 

The following program completes all 5 iterations.  

#!/usr/bin/python3
stack = [s for s in range(5)]
c = 0
for i in stack:
  c += 1
  print(f"{'='*10} loop {c} {'='*10}")
  if i == 0 or i == 1 or i == 2:
print(f"{i}\n")
  else:
print(f"{i}\n")


$ python3 test1.py 
== loop 1 ==
0

== loop 2 ==
1

== loop 3 ==
2

== loop 4 ==
3

== loop 5 ==
4

--

___
Python tracker 
<https://bugs.python.org/issue41518>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41518] incorrect printing behavior with parenthesis symbols

2020-08-11 Thread Ramesh Sahoo


Ramesh Sahoo  added the comment:

Hi all,

Thanks for your valuable response. I would like to inform you that I found this 
issue while playing with the following code. This is reproducible with Python 
3.8. 

Please find the following details and let me know if I am doing something 
wrong. 


[Using for loop popping elements]

import sys
stack,braces = [],{'(':')','{':'}','[':']'}
stack = [s for s in "(([])"]
c = 0
print(f"Python version: {sys.version}")
print(f"Before for loop:\nbraces.keys = {braces.keys()}\nbraces.items = 
{braces.items()}\nstack = {stack}\n\n")

for i in stack:
c += 1
print(f"{'='*10} loop {c} {'='*10}")
print("just after for loop stack =",stack)
print(f"Just after for loop i =",i)
print(f"Just after for loop: Is i'{i}' found in braces.keys:{i in 
braces.keys()}")

if i in braces.keys():
print(f"inside if i = {i}")
print("inside if stack =",stack)
print("inside if Popped =",stack.pop(stack.index(i)))
print(f"inside if after popped stack = {stack}\n")
continue

else:
print(f"in else: Is i'{i}' found in braces.keys:{i in braces.keys()}")
print(f"in else stack = {stack}\n")


[Program Output]

$ python3 test1.py 

Python version: 3.8.0 (default, Nov 14 2019, 22:29:45) 
[GCC 5.4.0 20160609]

Before for loop:
braces.keys = dict_keys(['(', '{', '['])
braces.items = dict_items([('(', ')'), ('{', '}'), ('[', ']')])
stack = ['(', '(', '[', ']', ')']

== loop 1 ==
just after for loop stack = ['(', '(', '[', ']', ')']
Just after for loop i = (
Just after for loop: Is i'(' found in braces.keys:True
inside if i = (
inside if stack = ['(', '(', '[', ']', ')']
inside if Popped = (
inside if after popped stack = ['(', '[', ']', ')']

== loop 2 ==
just after for loop stack = ['(', '[', ']', ')']
Just after for loop i = [
Just after for loop: Is i'[' found in braces.keys:True
inside if i = [
inside if stack = ['(', '[', ']', ')']
inside if Popped = [
inside if after popped stack = ['(', ']', ')']

== loop 3 ==
just after for loop stack = ['(', ']', ')']
Just after for loop i = )
Just after for loop: Is i')' found in braces.keys:False
in else: Is i')' found in braces.keys:False
in else stack = ['(', ']', ')']


[Summary]

stack = ['(', '(', '[', ']', ')']
=> [loop 1] is correct where the right element "(" has been popped.

['(', '[', ']', ')']
=> [loop 2] "(" element should have been popped but "[" chosen to be popped. 
This seems to be incorrect.

=> There must be 5 iterations(3 in if block and 2 in else block) but loop 
completed with 3 iterations(2 in if and one in else).  


I am not sure if I am doing something wrong or it is a buggy behavior. 



[Popping elements manually gives correct behavior]

import sys
print(f"Python Version: {sys.version}")

stack,braces = [],{'(':')','{':'}','[':']'}
stack = [s for s in "(([])"]

print(f"Original:\nbraces.keys = {braces.keys()}\nbraces.items = 
{braces.items()}\nstack = {stack}\n\n")

# Popping '('
print(f"Popped {stack.pop(stack.index('('))}")
print(f"stack after popping '(' = {stack}")

# Popping '('
print(f"Popped {stack.pop(stack.index('('))}")
print(f"stack after popping '(' = {stack}")

# Popping '['
print(f"Popped {stack.pop(stack.index('['))}")
print(f"stack after popping '[' = {stack}")


[Program Output]
Python Version: 3.8.0 (default, Nov 14 2019, 22:29:45) 
[GCC 5.4.0 20160609]
Original:
braces.keys = dict_keys(['(', '{', '['])
braces.items = dict_items([('(', ')'), ('{', '}'), ('[', ']')])
stack = ['(', '(', '[', ']', ')']
Popped (
stack after popping '(' = ['(', '[', ']', ')']
Popped (
stack after popping '(' = ['[', ']', ')']
Popped [
stack after popping '[' = [']', ')']

--
status: closed -> open
versions: +Python 3.8 -Python 3.6

___
Python tracker 
<https://bugs.python.org/issue41518>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41518] incorrect printing behavior with parenthesis symbols

2020-08-11 Thread Ramesh Sahoo


Change by Ramesh Sahoo :


--
resolution: works for me -> 

___
Python tracker 
<https://bugs.python.org/issue41518>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue41518] incorrect printing behavior with parenthesis symbols

2020-08-10 Thread Ramesh Sahoo


New submission from Ramesh Sahoo :

With for loop, I am able to print all elements in the list 'a'

a = ['a','a','b','b','c']
for i in a:
print(i)

O/P: 

a
a
b
b
c

but with the following loop, python only prints 3 uniq elements instead of 5. 

stack = ['(', '(', '[', ']', ')']
for i in stack:
print(i)

O/P: 
(
]
)


Is this is intended behavior?

--
messages: 375136
nosy: rameshsahoo11
priority: normal
severity: normal
status: open
title: incorrect printing behavior with parenthesis symbols
type: behavior
versions: Python 3.6

___
Python tracker 
<https://bugs.python.org/issue41518>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com