Skip to main content
Commonmark migration
Source Link

Python 49 45 18 22 15 14

##( + 3 if string variables are considered)##

( + 3 if string variables are considered)

print{a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be pre-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

( + 3 if string variables are considered)

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using pre-initialized variables.

Python 49 45 18 22 15 14

##( + 3 if string variables are considered)##

print{a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be pre-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using pre-initialized variables.

Python 49 45 18 22 15 14

( + 3 if string variables are considered)

print{a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be pre-initialized to the strings.


Python shell, 9

( + 3 if string variables are considered)

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using pre-initialized variables.

Python doesn't care about whitespace, so shorten code by one byte.
Source Link
null
  • 12.2k
  • 3
  • 58
  • 93

Python 49 45 18 22 15 1514

##( + 3 if string variables are considered)##

print {a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be pre-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using pre-initialized variables.

Python 49 45 18 22 15

##( + 3 if string variables are considered)##

print {a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be pre-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using pre-initialized variables.

Python 49 45 18 22 15 14

##( + 3 if string variables are considered)##

print{a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be pre-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using pre-initialized variables.

edited body
Source Link
user80551
  • 2.6k
  • 18
  • 26

Python 49 45 18 22 15

##( + 3 if string variables are considered)##

print {a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be perpre-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using perpre-initialized variables.

Python 49 45 18 22 15

##( + 3 if string variables are considered)##

print {a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be per-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using per-initialized variables.

Python 49 45 18 22 15

##( + 3 if string variables are considered)##

print {a:0,b:1}[a]

The string should be hard coded at the two occurrences of a and one occurrence of b surrounded by quotes.

a and b should be pre-initialized to the strings.


Python shell, 9

##( + 3 if string variables are considered) ##

{a:0,b:1}[a]

Output in shell

>>> a = 'string'
>>> b = 'string'
>>> {a:0,b:1}[a]
1
>>> a = 'string'
>>> b = 'stringgg'
>>> {a:0,b:1}[a]
0
>>> {'string':0,'string':1}['string']
1
>>> {'stringggg':0,'string':1}['stringggg']
0
>>> 

Explanation

Creates a dict(hash table) with the key of first and second string. If second string is the same, the value of first is replaced by that of second. Finally, we print the value of first key.

EDIT: OP allowed 0/1 instead of False/True as well as using pre-initialized variables.

deleted 51 characters in body
Source Link
user80551
  • 2.6k
  • 18
  • 26
Loading
deleted 3 characters in body
Source Link
user80551
  • 2.6k
  • 18
  • 26
Loading
deleted 3 characters in body
Source Link
user80551
  • 2.6k
  • 18
  • 26
Loading
edited body
Source Link
user80551
  • 2.6k
  • 18
  • 26
Loading
added 7 characters in body
Source Link
user80551
  • 2.6k
  • 18
  • 26
Loading
deleted 235 characters in body
Source Link
user80551
  • 2.6k
  • 18
  • 26
Loading
Source Link
user80551
  • 2.6k
  • 18
  • 26
Loading