I pass a list to a function and look at the output. When the list is hardcoded, I've got the expected output. But when I build the list from a string, and pass that list with the same content to the function, I don't have the expected output.
First call:
tech = [ "Django", "Zend", "SQLite", "foo" ]
for tech_item in tech:
print( test_main( tech_item ) )
Second call:
raw_txt = "Django,Zend,SQLite,foo"
tech = raw_txt.split( "," )
# At this point if we print "tech" we have:
# [ "Django", "Zend", "SQLite", "foo" ]
for tech_item in tech:
print( test_main( tech_item ) )
So, the input is/seems to be identical, but the output is different.
When I compare the content of the two lists (renaming the second list: tech2) I have:
print( tech[0], tech2[0] ) #Django Django
print( tech[0] == tech2[0] ) #True
print( type(tech[0]), type(tech2[0]) ) #<class 'str'> <class 'str'>
print( len(tech[0]), len(tech2[0]) ) #6 6
What am I missing? Do you have any clue on how to find/resolve this?
Edit:
Output I've got for the 1st case:
frameworks
frameworks
SQL
None
Output I've got for the 2nd case:
None
None
None
None
test_main function
I give you the test_main function, but I'm afraid it is going to confuse you. So, "looking_for" is the same each time. But "tmp" is different in both cases.
def test_main( looking_for ):
global tmp
tmp = None
get_recursively( languages_tech, looking_for )
return tmp
get_recursively function
def get_recursively( data, looking_for, last_key="" ):
if not isinstance( data, (list, dict) ):
if data is looking_for: #item
global tmp
tmp = last_key
else:
if isinstance( data, dict ): #Dictionaries
for key, value in data.items():
get_recursively( value, looking_for, key )
else:
for item in data: #list
get_recursively( item, looking_for, last_key )
Languages_tech
languages = { "languages": [
"Ruby", "Python", "JavaScript", "ASP.NET", "Java", "C", "C++", "C#", "Swift", "PHP", "Visual Basic", "Bash" ] }
frameworks = { "frameworks" : [
"Django", "Flask", "React", "React Native", "Vue", "Ember", "Meteor", "AngularJS", "Express" , "Laravel", "Symfony", "Zend", "Ruby on Rails" ] }
databases = { "databases" : [
{ "SQL": ["MariaDB", "MySQL", "SQLite", "PostgreSQL", "Oracle", "MSSQL Server"] },
{ "NoSQL": ["Cassandra", "CouchDB", "MongoDB", "Neo4j", "OrientDB", "Redis", "Elasticsearch"] },
{ "ORM Framework": [ "SQLAlchemy", "Django ORM" ] } ] }
languages_tech = { "languages_tech": [ languages, frameworks, databases ] }