Post History
Python 3.8 (pre-release), 69 bytes def f(x,y={},z=[]): for i in x:y[i]=y.get(i,0)+1;z+=[y[i]] return z Try it online! Bonus: theoretical answer if python allowed named assignment with su...
Answer
#7: Post edited
# [Python 3.8 (pre-release)], 70 bytes- <!-- language-all: lang-python -->
def f(x):y={};z=[]- for i in x:y[i]=y.get(i,0)+1;z+=[y[i]]
- return z
[Try it online!][TIO-lajv4jy0]- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
[TIO-lajv4jy0]: https://tio.run/##PYrBDsIgEAXvfMUeId0YEa21DV9CuAnKhZINJgXjtyP2YCbv8mZSyc81qilRa3fnwfNNzAyKfn@Wqo1l4FeCACHCNhcTrC6Hh8s84FEMcqmDNr@3d@TyiyLUlijEzD03EiWeduSOQmWFYH@v8IoXPOOtF6pvxLH79gU "Python 3.8 (pre-release) – Try It Online"- Bonus: theoretical answer if python allowed named assignment with subscript (54 bytes)
- ```python
- lambda x,y={}:[y[i]:=y[i]+1if i in y else 1for i in x]
- ```
- # [Python 3.8 (pre-release)], 69 bytes
- <!-- language-all: lang-python -->
- def f(x,y={},z=[]):
- for i in x:y[i]=y.get(i,0)+1;z+=[y[i]]
- return z
- [Try it online!][TIO-lajvuuzr]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lajvuuzr]: https://tio.run/##PYrRCsIgGEbvfYofdqPsJzJrq4WXPYV4sUhLWG6IwVz07Ga7iMP3XRzOlOJj9OI4hZxvxoKlMyb5/uAilWYdATsGcOA8zF1STsu0uZtIHW5Zzc9LLdXPagLBxFfwsOQKLr6/DgZGP6RyBvoIPUT3NGQKzkdqqeLIcbfCVwQKzRip/oHAFg@4x1NJRFmDTQnyFw "Python 3.8 (pre-release) – Try It Online"
- Bonus: theoretical answer if python allowed named assignment with subscript (54 bytes)
- ```python
- lambda x,y={}:[y[i]:=y[i]+1if i in y else 1for i in x]
- ```
#6: Post edited
# [Python 3.8], 88 bytes- <!-- language-all: lang-python -->
- def f(x):
y={}z=[]for i in x:y[i]=y[i]+1 if i in y else 1z+=[y[i]]- return z
[Try it online!][TIO-l613yp1s][Python 3.8]: https://docs.python.org/3.8/[TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"- Bonus: theoretical answer if python allowed named assignment with subscript (54 bytes)
- ```python
- lambda x,y={}:[y[i]:=y[i]+1if i in y else 1for i in x]
- ```
- # [Python 3.8 (pre-release)], 70 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={};z=[]
- for i in x:y[i]=y.get(i,0)+1;z+=[y[i]]
- return z
- [Try it online!][TIO-lajv4jy0]
- [Python 3.8 (pre-release)]: https://docs.python.org/3.8/
- [TIO-lajv4jy0]: https://tio.run/##PYrBDsIgEAXvfMUeId0YEa21DV9CuAnKhZINJgXjtyP2YCbv8mZSyc81qilRa3fnwfNNzAyKfn@Wqo1l4FeCACHCNhcTrC6Hh8s84FEMcqmDNr@3d@TyiyLUlijEzD03EiWeduSOQmWFYH@v8IoXPOOtF6pvxLH79gU "Python 3.8 (pre-release) – Try It Online"
- Bonus: theoretical answer if python allowed named assignment with subscript (54 bytes)
- ```python
- lambda x,y={}:[y[i]:=y[i]+1if i in y else 1for i in x]
- ```
#5: Post edited
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
- [Python 3.8]: https://docs.python.org/3.8/
[TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
- [Python 3.8]: https://docs.python.org/3.8/
- [TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"
- Bonus: theoretical answer if python allowed named assignment with subscript (54 bytes)
- ```python
- lambda x,y={}:[y[i]:=y[i]+1if i in y else 1for i in x]
- ```
#4: Post edited
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
Theoretical answer if python allowed assignment expressions with subscripts (44 bytes):```pythonlambda x,y={}:[y[i]:=y[i]+1if i in y else 1]```- [Python 3.8]: https://docs.python.org/3.8/
- [TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
- [Python 3.8]: https://docs.python.org/3.8/
- [TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"
#3: Post edited
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
Theoretical answer if python allowed assignment expressions with subscripts (45 bytes):- ```python
lambda x,y={}:[y[i]:=y[i]+1 if i in y else 1]- ```
- [Python 3.8]: https://docs.python.org/3.8/
- [TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
- Theoretical answer if python allowed assignment expressions with subscripts (44 bytes):
- ```python
- lambda x,y={}:[y[i]:=y[i]+1if i in y else 1]
- ```
- [Python 3.8]: https://docs.python.org/3.8/
- [TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"
#2: Post edited
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
[Python 3.8 (pre-release)]: https://docs.python.org/3.8/[TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"- Theoretical answer if python allowed assignment expressions with subscripts (45 bytes):
- ```python
- lambda x,y={}:[y[i]:=y[i]+1 if i in y else 1]
```
- # [Python 3.8], 88 bytes
- <!-- language-all: lang-python -->
- def f(x):
- y={}
- z=[]
- for i in x:
- y[i]=y[i]+1 if i in y else 1
- z+=[y[i]]
- return z
- [Try it online!][TIO-l613yp1s]
- Theoretical answer if python allowed assignment expressions with subscripts (45 bytes):
- ```python
- lambda x,y={}:[y[i]:=y[i]+1 if i in y else 1]
- ```
- [Python 3.8]: https://docs.python.org/3.8/
- [TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online"
#1: Initial revision
# [Python 3.8], 88 bytes <!-- language-all: lang-python --> def f(x): y={} z=[] for i in x: y[i]=y[i]+1 if i in y else 1 z+=[y[i]] return z [Try it online!][TIO-l613yp1s] [Python 3.8 (pre-release)]: https://docs.python.org/3.8/ [TIO-l613yp1s]: https://tio.run/##PcvBCgIhFAXQvV9xlyPzNmZNNeCXiLuUhHDEDEajbzdngri8uznvxpLvS5CXmFq7WQc3rHxmKOr9YahKGwa3JHj4gHUGA4r2Rm01Cnj3kwL7eFqIznVUetM@TDa/UkBtMfmQBzdoQYIOe8QeSdJwzv4u6UwnOtK1f8h@E03d2xc "Python 3.8 (pre-release) – Try It Online" Theoretical answer if python allowed assignment expressions with subscripts (45 bytes): ```python lambda x,y={}:[y[i]:=y[i]+1 if i in y else 1] ```