Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
Code Golf

Return to Answer

added 185 characters in body
Source Link

Python 3, (削除) 159 (削除ここまで) (削除) 141 (削除ここまで) 152(削除) 152 (削除ここまで) 128 bytes

import ast
def f(s):
	g={}
	for k in s:
		if'='in k:
			*v,l=k.split('=')
			for r in v:
				try:g[r]=ast.literal_evalg[r]=int(l)
				except:g[r]=g[l]
	return g

Try it online! Try it online!

-18 bytes thanks to pxeger

+11 bytes thanks to Shaggy for pointing out a bug

-24 bytes thanks to ovs

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

Python 3, (削除) 159 (削除ここまで) (削除) 141 (削除ここまで) 152 bytes

import ast
def f(s):
	g={}
	for k in s:
		if'='in k:
			*v,l=k.split('=')
			for r in v:
				try:g[r]=ast.literal_eval(l)
				except:g[r]=g[l]
	return g

Try it online!

-18 bytes thanks to pxeger

+11 bytes thanks to Shaggy for pointing out a bug

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

Python 3, (削除) 159 (削除ここまで) (削除) 141 (削除ここまで) (削除) 152 (削除ここまで) 128 bytes

def f(s):
	g={}
	for k in s:
		if'='in k:
			*v,l=k.split('=')
			for r in v:
				try:g[r]=int(l)
				except:g[r]=g[l]
	return g

Try it online!

-18 bytes thanks to pxeger

+11 bytes thanks to Shaggy for pointing out a bug

-24 bytes thanks to ovs

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

added 292 characters in body
Source Link

Python 3, (削除) 159 (削除ここまで) 141(削除) 141 (削除ここまで) 152 bytes

import ast
def f(s,g={}):
	g={}
	for k in s:
		if'='in k:
			*v,l=k.split('=')
			for r in v:
				try:g[r]=ast.literal_eval(l)
				except:g[r]=g[l]
	return g

Try it online! Try it online!

-18 bytes thanks to pxeger

+11 bytes thanks to Shaggy for pointing out a bug

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

Python 3, (削除) 159 (削除ここまで) 141 bytes

import ast
def f(s,g={}):
	for k in s:
		if'='in k:
			*v,l=k.split('=')
			for r in v:
				try:g[r]=ast.literal_eval(l)
				except:g[r]=g[l]

Try it online!

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

Python 3, (削除) 159 (削除ここまで) (削除) 141 (削除ここまで) 152 bytes

import ast
def f(s):
	g={}
	for k in s:
		if'='in k:
			*v,l=k.split('=')
			for r in v:
				try:g[r]=ast.literal_eval(l)
				except:g[r]=g[l]
	return g

Try it online!

-18 bytes thanks to pxeger

+11 bytes thanks to Shaggy for pointing out a bug

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

added 238 characters in body
Source Link

Python 3, 159(削除) 159 (削除ここまで) 141 bytes

import ast
def f(s,g={}):
	for k in filter(lambda as:'='in
		if'='in a,s)k:
		*v			*v,l=k.split('=')
		for			for r in v:
			try				try:g[r]=ast.literal_eval(l)
			except				except:g[r]=g[l]
	return g

Try it online! Try it online!

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

Python 3, 159 bytes

import ast
def f(s,g={}):
	for k in filter(lambda a:'='in a,s):
		*v,l=k.split('=')
		for r in v:
			try:g[r]=ast.literal_eval(l)
			except:g[r]=g[l]
	return g

Try it online!

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

Python 3, (削除) 159 (削除ここまで) 141 bytes

import ast
def f(s,g={}):
	for k in s:
		if'='in k:
			*v,l=k.split('=')
			for r in v:
				try:g[r]=ast.literal_eval(l)
				except:g[r]=g[l]

Try it online!

Python really isn't my strong suit for golfing :/ Note the use of tabs rather than spaces, so the indentation levels are still a single byte each. Takes input as a list of lines with assignments separated by = (no spaces) and returns a dictionary of variables and values

added 19 characters in body
Source Link
Loading
deleted 59 characters in body
Source Link
Loading
Post Undeleted by caird coinheringaahing
deleted 59 characters in body
Source Link
Loading
Post Deleted by caird coinheringaahing
Source Link
Loading

AltStyle によって変換されたページ (->オリジナル) /