Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

50%
+0 −0
Challenges Cumulative Counts

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...

posted 1y ago by dino‭  ·  edited 1y ago by dino‭

Answer
#7: Post edited by user avatar dino‭ · 2022-11-16T16:54:03Z (over 1 year ago)
  • # [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 by user avatar dino‭ · 2022-11-16T16:33:53Z (over 1 year ago)
  • # [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]
  • ```
  • # [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 by user avatar dino‭ · 2022-08-23T13:40:43Z (over 1 year ago)
  • # [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 by user avatar dino‭ · 2022-08-08T17:12:01Z (over 1 year ago)
  • # [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"
  • # [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 by user avatar dino‭ · 2022-07-25T18:59:59Z (over 1 year ago)
  • # [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 by user avatar dino‭ · 2022-07-25T18:59:00Z (over 1 year ago)
  • # [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 by user avatar dino‭ · 2022-07-25T18:58:03Z (over 1 year ago)
# [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]
```